• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <errno.h>
2 #include <stddef.h>
3 #ifdef _WIN32
4 #include <windows.h>
5 #else
6 #include <sys/select.h>
7 #endif
8 
9 // Wait until file descriptor |fd| becomes readable.
yield_until_fd_readable(int fd)10 void yield_until_fd_readable(int fd) {
11     for (;;) {
12        fd_set read_fds;
13        FD_ZERO(&read_fds);
14        FD_SET(fd, &read_fds);
15        int ret = select(fd + 1, &read_fds, NULL, NULL, NULL);
16        if (ret == 1 || (ret < 0 && errno != -EINTR))
17            return;
18     }
19 }
20 
21