+#if USE_SELECT
+static int fakepoll(struct pollfd *fds, int nfds, int timeout) {
+ fd_set infds[1], outfds[1];
+ int maxfd = -1, i, rc;
+ struct timeval tvtimeout;
+ FD_ZERO(infds);
+ FD_ZERO(outfds);
+ for(i = 0; i < nfds; ++i) {
+ if(fds[i].events & POLLIN)
+ FD_SET(fds[i].fd, infds);
+ if(fds[i].events & POLLOUT)
+ FD_SET(fds[i].fd, outfds);
+ if(fds[i].fd > maxfd)
+ maxfd = fds[i].fd;
+ }
+ if(timeout != -1) {
+ tvtimeout.tv_sec = timeout / 1000;
+ tvtimeout.tv_usec = 1000 * (timeout % 1000);
+ }
+ rc = select(maxfd + 1, infds, outfds, NULL,
+ timeout == -1 ? NULL : &tvtimeout);
+ if(rc >= 0) {
+ for(i = 0; i < nfds; ++i) {
+ int revents = 0;
+ if(FD_ISSET(fds[i].fd, infds))
+ revents |= POLLIN;
+ if(FD_ISSET(fds[i].fd, outfds))
+ revents |= POLLOUT;
+ fds[i].revents = revents;
+ }
+ }
+ return rc;
+}
+#endif
+