Use poll() instead of select() if available

This commit is contained in:
Dmitry Stogov 2007-02-24 11:21:10 +00:00
parent 94c3896f73
commit 10ffce3285

View File

@ -71,6 +71,13 @@
# include <netdb.h>
# include <signal.h>
# if defined(HAVE_SYS_POLL_H) && defined(HAVE_POLL)
# include <sys/poll.h>
# endif
# if defined(HAVE_SYS_SELECT_H)
# include <sys/select.h>
# 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.");