aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2015-12-08 20:02:43 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2015-12-08 20:02:43 +0000
commit8ace389d37855f16c9bef7afd70304b8d5c7da4e (patch)
tree1510e84330f1e900275b60193210022e9975d4be
parent855576097efd75d62c81fd3cb9db5191b16b8707 (diff)
downloadlibmicrohttpd-8ace389d37855f16c9bef7afd70304b8d5c7da4e.tar.gz
libmicrohttpd-8ace389d37855f16c9bef7afd70304b8d5c7da4e.zip
MHD_select(): handle at least some of pending connections instead of failing without any data processing
-rw-r--r--src/microhttpd/daemon.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 0aa0f8aa..209f8e5d 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2322,6 +2322,7 @@ MHD_select (struct MHD_Daemon *daemon,
2322 struct timeval timeout; 2322 struct timeval timeout;
2323 struct timeval *tv; 2323 struct timeval *tv;
2324 MHD_UNSIGNED_LONG_LONG ltimeout; 2324 MHD_UNSIGNED_LONG_LONG ltimeout;
2325 int err_state;
2325 2326
2326 timeout.tv_sec = 0; 2327 timeout.tv_sec = 0;
2327 timeout.tv_usec = 0; 2328 timeout.tv_usec = 0;
@@ -2331,6 +2332,7 @@ MHD_select (struct MHD_Daemon *daemon,
2331 FD_ZERO (&ws); 2332 FD_ZERO (&ws);
2332 FD_ZERO (&es); 2333 FD_ZERO (&es);
2333 maxsock = MHD_INVALID_SOCKET; 2334 maxsock = MHD_INVALID_SOCKET;
2335 err_state = MHD_NO;
2334 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2336 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2335 { 2337 {
2336 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) && 2338 if ( (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME)) &&
@@ -2343,7 +2345,7 @@ MHD_select (struct MHD_Daemon *daemon,
2343#if HAVE_MESSAGES 2345#if HAVE_MESSAGES
2344 MHD_DLOG (daemon, "Could not obtain daemon fdsets"); 2346 MHD_DLOG (daemon, "Could not obtain daemon fdsets");
2345#endif 2347#endif
2346 return MHD_NO; 2348 err_state = MHD_YES;
2347 } 2349 }
2348 2350
2349 /* If we're at the connection limit, no need to 2351 /* If we're at the connection limit, no need to
@@ -2394,7 +2396,7 @@ MHD_select (struct MHD_Daemon *daemon,
2394 MHD_DLOG (daemon, 2396 MHD_DLOG (daemon,
2395 "Could not add control pipe FD to fdset"); 2397 "Could not add control pipe FD to fdset");
2396#endif 2398#endif
2397 return MHD_NO; 2399 err_state = MHD_YES;
2398#if defined(MHD_WINSOCK_SOCKETS) 2400#if defined(MHD_WINSOCK_SOCKETS)
2399 } 2401 }
2400 } 2402 }
@@ -2402,6 +2404,8 @@ MHD_select (struct MHD_Daemon *daemon,
2402 } 2404 }
2403 2405
2404 tv = NULL; 2406 tv = NULL;
2407 if (MHD_YES == err_state)
2408 may_block = MHD_NO;
2405 if (MHD_NO == may_block) 2409 if (MHD_NO == may_block)
2406 { 2410 {
2407 timeout.tv_usec = 0; 2411 timeout.tv_usec = 0;
@@ -2425,7 +2429,7 @@ MHD_select (struct MHD_Daemon *daemon,
2425 if (num_ready < 0) 2429 if (num_ready < 0)
2426 { 2430 {
2427 if (EINTR == MHD_socket_errno_) 2431 if (EINTR == MHD_socket_errno_)
2428 return MHD_YES; 2432 return (MHD_NO == err_state) ? MHD_YES : MHD_NO;
2429#if HAVE_MESSAGES 2433#if HAVE_MESSAGES
2430 MHD_DLOG (daemon, 2434 MHD_DLOG (daemon,
2431 "select failed: %s\n", 2435 "select failed: %s\n",
@@ -2433,7 +2437,9 @@ MHD_select (struct MHD_Daemon *daemon,
2433#endif 2437#endif
2434 return MHD_NO; 2438 return MHD_NO;
2435 } 2439 }
2436 return MHD_run_from_select (daemon, &rs, &ws, &es); 2440 if (MHD_YES == MHD_run_from_select (daemon, &rs, &ws, &es))
2441 return (MHD_NO == err_state) ? MHD_YES : MHD_NO;
2442 return MHD_NO;
2437} 2443}
2438 2444
2439 2445