select.c 568 B

123456789101112131415161718192021222324
  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <sys/select.h>
  4. #include <unistd.h>
  5. #include "test_helpers.h"
  6. int main(void) {
  7. int fd = open("select.c", 0, 0);
  8. fd_set read;
  9. FD_ZERO(&read);
  10. FD_SET(fd, &read);
  11. printf("Is set before? %d\n", FD_ISSET(fd, &read));
  12. // This should actually test TCP streams and stuff, but for now I'm simply
  13. // testing whether it ever returns or not.
  14. printf("Amount of things ready: %d\n", select(fd + 1, &read, NULL, NULL, NULL));
  15. printf("Is set after? %d\n", FD_ISSET(fd, &read));
  16. close(fd);
  17. }