+
+ if (timeout < 0)
+ rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
+ else {
+ struct timeval tv;
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = 1000 * (timeout % 1000);
+ rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
+ };
+
+ if (rc < 0)
+ return rc;
+
+ for(i = 0; i < (nfds_t) n; i++) {
+ fds[i].revents = 0;
+
+ if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN;
+ if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT;
+ if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR;
+ };
+
+ return rc;