diff --git src/ae.c src/ae.c --- src/ae.c +++ src/ae.c @@ -474,21 +474,44 @@ int aeProcessEvents(aeEventLoop *eventLoop, int flags) /* Wait for milliseconds until the given file descriptor becomes * writable/readable/exception */ int aeWait(int fd, int mask, long long milliseconds) { + int retmask = 0, retval; + short revents = 0; +#ifdef _WINSOCKAPI_ + fd_set rset, wset; + FD_ZERO(&rset); + FD_ZERO(&wset); + if (mask & AE_READABLE) { + FD_SET(fd, &rset); + } else if (mask & AE_WRITABLE) { + FD_SET(fd, &wset); + } + struct timeval tv = { milliseconds / 1000, (milliseconds % 1000) * 1000 }; + if ((retval = select(fd + 1, &rset, &wset, NULL, milliseconds >= 0 ? &tv : NULL)) > 0) { + if (FD_ISSET(fd, &rset)) { + revents |= POLLIN; + } + if (FD_ISSET(fd, &wset)) { + revents |= POLLOUT; + } + } +#else struct pollfd pfd; - int retmask = 0, retval; memset(&pfd, 0, sizeof(pfd)); pfd.fd = fd; if (mask & AE_READABLE) pfd.events |= POLLIN; if (mask & AE_WRITABLE) pfd.events |= POLLOUT; + retval = poll(&pfd, 1, milliseconds); + revents = pfd.revents; - if ((retval = poll(&pfd, 1, milliseconds))== 1) { - if (pfd.revents & POLLIN) retmask |= AE_READABLE; - if (pfd.revents & POLLOUT) retmask |= AE_WRITABLE; - if (pfd.revents & POLLERR) retmask |= AE_WRITABLE; - if (pfd.revents & POLLHUP) retmask |= AE_WRITABLE; +#endif + if (retval== 1) { + if (revents & POLLIN) retmask |= AE_READABLE; + if (revents & POLLOUT) retmask |= AE_WRITABLE; + if (revents & POLLERR) retmask |= AE_WRITABLE; + if (revents & POLLHUP) retmask |= AE_WRITABLE; return retmask; } else { return retval; } } --