mirror of
https://github.com/php/php-src.git
synced 2025-01-11 05:24:49 +08:00
Use poll() instead of select() if available
This commit is contained in:
parent
94c3896f73
commit
10ffce3285
@ -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:
|
||||
do {
|
||||
errno = 0;
|
||||
if (select(req->fd + 1, &set, NULL, NULL, &tv) >= 0 && FD_ISSET(req->fd, &set)) {
|
||||
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.");
|
||||
|
Loading…
Reference in New Issue
Block a user