#include #include #include static int countset(int nfds, fd_set *set) { int count = 0; if (set == NULL) return 0; for (int i = 0; i < nfds; i++) { if (FD_ISSET(i, set)) { count++; } } return count; } int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { (void)timeout; FD_ZERO(exceptfds); if (countset(nfds, readfds) != 0) { if (countset(nfds, readfds) == 1 && countset(nfds, writefds) == 0) { /* special case: if you're only waiting for a single fd to become * readable, just go ahead and read() it. * curl compat. */ return 1; } return errno = ENOSYS, -1; } return countset(nfds, writefds); /* assume everything is ready for writing */ } void FD_CLR(int fd, fd_set *set) { if (0 <= fd && fd < FD_SETSIZE) { *set = *set & ~(1<