2
0

select.c 541 B

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