diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 076a7ada..eef9eca8 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -650,22 +650,12 @@ add_to_fd_set (MHD_socket fd, | |||
650 | MHD_socket *max_fd, | 650 | MHD_socket *max_fd, |
651 | unsigned int fd_setsize) | 651 | unsigned int fd_setsize) |
652 | { | 652 | { |
653 | if (NULL == set) | 653 | if (NULL == set || MHD_INVALID_SOCKET == fd) |
654 | return MHD_NO; | 654 | return MHD_NO; |
655 | #ifdef MHD_WINSOCK_SOCKETS | 655 | if (!MHD_SCKT_FD_FITS_FDSET_SETSIZE_(fd, set, fd_setsize)) |
656 | if (set->fd_count >= fd_setsize) | ||
657 | { | ||
658 | if (FD_ISSET(fd, set)) | ||
659 | return MHD_YES; | ||
660 | else | ||
661 | return MHD_NO; | ||
662 | } | ||
663 | #else /* ! MHD_WINSOCK_SOCKETS */ | ||
664 | if (fd >= (MHD_socket)fd_setsize) | ||
665 | return MHD_NO; | 656 | return MHD_NO; |
666 | #endif /* ! MHD_WINSOCK_SOCKETS */ | 657 | MHD_SCKT_ADD_FD_TO_FDSET_SETSIZE_(fd, set, fd_setsize); |
667 | FD_SET (fd, set); | 658 | if ( (NULL != max_fd) && |
668 | if ( (NULL != max_fd) && (MHD_INVALID_SOCKET != fd) && | ||
669 | ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) ) | 659 | ((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) ) |
670 | *max_fd = fd; | 660 | *max_fd = fd; |
671 | 661 | ||
@@ -1325,15 +1315,14 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1325 | return MHD_NO; | 1315 | return MHD_NO; |
1326 | } | 1316 | } |
1327 | 1317 | ||
1328 | #ifndef MHD_WINSOCK_SOCKETS | 1318 | if ( (!MHD_SCKT_FD_FITS_FDSET_(client_socket, NULL)) && |
1329 | if ( (client_socket >= FD_SETSIZE) && | ||
1330 | (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) ) | 1319 | (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) ) |
1331 | { | 1320 | { |
1332 | #ifdef HAVE_MESSAGES | 1321 | #ifdef HAVE_MESSAGES |
1333 | MHD_DLOG (daemon, | 1322 | MHD_DLOG (daemon, |
1334 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", | 1323 | "Socket descriptor larger than FD_SETSIZE: %d > %d\n", |
1335 | client_socket, | 1324 | (int)client_socket, |
1336 | FD_SETSIZE); | 1325 | (int)FD_SETSIZE); |
1337 | #endif | 1326 | #endif |
1338 | if (0 != MHD_socket_close_ (client_socket)) | 1327 | if (0 != MHD_socket_close_ (client_socket)) |
1339 | MHD_PANIC ("close failed\n"); | 1328 | MHD_PANIC ("close failed\n"); |
@@ -1342,7 +1331,6 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1342 | #endif | 1331 | #endif |
1343 | return MHD_NO; | 1332 | return MHD_NO; |
1344 | } | 1333 | } |
1345 | #endif | ||
1346 | 1334 | ||
1347 | 1335 | ||
1348 | #ifdef HAVE_MESSAGES | 1336 | #ifdef HAVE_MESSAGES |
@@ -2267,7 +2255,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon, | |||
2267 | { | 2255 | { |
2268 | /* we're in epoll mode, the epoll FD stands for | 2256 | /* we're in epoll mode, the epoll FD stands for |
2269 | the entire event set! */ | 2257 | the entire event set! */ |
2270 | if (daemon->epoll_fd >= FD_SETSIZE) | 2258 | if (!MHD_SCKT_FD_FITS_FDSET_(daemon->epoll_fd, NULL)) |
2271 | return MHD_NO; /* poll fd too big, fail hard */ | 2259 | return MHD_NO; /* poll fd too big, fail hard */ |
2272 | if (FD_ISSET (daemon->epoll_fd, read_fd_set)) | 2260 | if (FD_ISSET (daemon->epoll_fd, read_fd_set)) |
2273 | return MHD_run (daemon); | 2261 | return MHD_run (daemon); |
@@ -3772,10 +3760,9 @@ MHD_start_daemon_va (unsigned int flags, | |||
3772 | } | 3760 | } |
3773 | make_nonblocking (daemon, daemon->wpipe[1]); | 3761 | make_nonblocking (daemon, daemon->wpipe[1]); |
3774 | } | 3762 | } |
3775 | #ifndef MHD_WINSOCK_SOCKETS | ||
3776 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) && | 3763 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) && |
3777 | (1 == use_pipe) && | 3764 | (1 == use_pipe) && |
3778 | (daemon->wpipe[0] >= FD_SETSIZE) ) | 3765 | (!MHD_SCKT_FD_FITS_FDSET_(daemon->wpipe[0], NULL)) ) |
3779 | { | 3766 | { |
3780 | #ifdef HAVE_MESSAGES | 3767 | #ifdef HAVE_MESSAGES |
3781 | MHD_DLOG (daemon, | 3768 | MHD_DLOG (daemon, |
@@ -3788,7 +3775,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
3788 | free (daemon); | 3775 | free (daemon); |
3789 | return NULL; | 3776 | return NULL; |
3790 | } | 3777 | } |
3791 | #endif | ||
3792 | #ifdef DAUTH_SUPPORT | 3778 | #ifdef DAUTH_SUPPORT |
3793 | daemon->digest_auth_rand_size = 0; | 3779 | daemon->digest_auth_rand_size = 0; |
3794 | daemon->digest_auth_random = NULL; | 3780 | daemon->digest_auth_random = NULL; |
@@ -4131,8 +4117,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4131 | goto free_and_fail; | 4117 | goto free_and_fail; |
4132 | } | 4118 | } |
4133 | } | 4119 | } |
4134 | #ifndef MHD_WINSOCK_SOCKETS | 4120 | if ( (!MHD_SCKT_FD_FITS_FDSET_(socket_fd, NULL)) && |
4135 | if ( (socket_fd >= FD_SETSIZE) && | ||
4136 | (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY)) ) ) | 4121 | (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY)) ) ) |
4137 | { | 4122 | { |
4138 | #ifdef HAVE_MESSAGES | 4123 | #ifdef HAVE_MESSAGES |
@@ -4145,7 +4130,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
4145 | MHD_PANIC ("close failed\n"); | 4130 | MHD_PANIC ("close failed\n"); |
4146 | goto free_and_fail; | 4131 | goto free_and_fail; |
4147 | } | 4132 | } |
4148 | #endif | ||
4149 | 4133 | ||
4150 | #if EPOLL_SUPPORT | 4134 | #if EPOLL_SUPPORT |
4151 | if ( (0 != (flags & MHD_USE_EPOLL_LINUX_ONLY)) && | 4135 | if ( (0 != (flags & MHD_USE_EPOLL_LINUX_ONLY)) && |
@@ -4293,9 +4277,8 @@ MHD_start_daemon_va (unsigned int flags, | |||
4293 | } | 4277 | } |
4294 | make_nonblocking (d, d->wpipe[1]); | 4278 | make_nonblocking (d, d->wpipe[1]); |
4295 | } | 4279 | } |
4296 | #ifndef MHD_WINSOCK_SOCKETS | ||
4297 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) && | 4280 | if ( (0 == (flags & (MHD_USE_POLL | MHD_USE_EPOLL_LINUX_ONLY))) && |
4298 | (d->wpipe[0] >= FD_SETSIZE) ) | 4281 | (!MHD_SCKT_FD_FITS_FDSET_(d->wpipe[0], NULL)) ) |
4299 | { | 4282 | { |
4300 | #ifdef HAVE_MESSAGES | 4283 | #ifdef HAVE_MESSAGES |
4301 | MHD_DLOG (daemon, | 4284 | MHD_DLOG (daemon, |
@@ -4307,7 +4290,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
4307 | MHD_PANIC ("close failed\n"); | 4290 | MHD_PANIC ("close failed\n"); |
4308 | goto thread_failed; | 4291 | goto thread_failed; |
4309 | } | 4292 | } |
4310 | #endif | ||
4311 | 4293 | ||
4312 | /* Divide available connections evenly amongst the threads. | 4294 | /* Divide available connections evenly amongst the threads. |
4313 | * Thread indexes in [0, leftover_conns) each get one of the | 4295 | * Thread indexes in [0, leftover_conns) each get one of the |