From: Dmitry Stogov Date: Sat, 24 Feb 2007 11:21:10 +0000 (+0000) Subject: Use poll() instead of select() if available X-Git-Tag: RELEASE_1_0_1~172 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10ffce328593ddda1fb31482ec5d19ce6e02556d;p=php Use poll() instead of select() if available --- diff --git a/sapi/cgi/fastcgi.c b/sapi/cgi/fastcgi.c index 3ac12a2def..7bbabb1127 100644 --- a/sapi/cgi/fastcgi.c +++ b/sapi/cgi/fastcgi.c @@ -71,6 +71,13 @@ # include # include +# if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) +# include +# endif +# if defined(HAVE_SYS_SELECT_H) +# include +# endif + #ifndef INADDR_NONE #define INADDR_NONE ((unsigned long) -1) #endif @@ -758,17 +765,35 @@ int fcgi_accept_request(fcgi_request *req) #else if (req->fd >= 0) { if (req->fd < FD_SETSIZE) { +#if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL) + struct pollfd fds; + int ret; + + fds.fd = req->fd; + fds.events = POLLIN; + fds.revents = 0; + do { + errno = 0; + ret = poll(&fds, 1, 5000); + } while (ret < 0 && errno == EINTR); + if (ret > 0 && (fds.revents & POLLIN)) { + break; + } +#else struct timeval tv = {5,0}; fd_set set; + int ret; FD_ZERO(&set); FD_SET(req->fd, &set); -try_again: - errno = 0; - if (select(req->fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(req->fd, &set)) { + do { + errno = 0; + ret = select(req->fd + 1, &set, NULL, NULL, &tv) >= 0; + } while (ret < 0 && errno == EINTR); + if (ret > 0 && FD_ISSET(req->fd, &set)) { break; } - if (errno == EINTR) goto try_again; +#endif fcgi_close(req, 1, 0); } else { fprintf(stderr, "Too many open file descriptors. FD_SETSIZE limit exceeded.");