commit 313e750c65cecfce85c1eed4f73c71196fecbac8
parent d196c6cd6428ebb36a0bd90bfcd0bad422ef09ef
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date: Sat, 21 Jan 2017 21:42:05 +0300
Fixed processing epoll with many connections to accept.
If 'accept_pending' were set to 'true' not connection transfer occurred.
Additionally 'accept_pending' never reset to false.
Diffstat:
2 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
@@ -3691,7 +3691,6 @@ MHD_epoll (struct MHD_Daemon *daemon,
MHD_UNSIGNED_LONG_LONG timeout_ll;
int num_events;
unsigned int i;
- unsigned int series_length;
#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
int run_upgraded = MHD_NO;
#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */
@@ -3830,26 +3829,18 @@ MHD_epoll (struct MHD_Daemon *daemon,
MHD_itc_clear_ (daemon->itc);
continue;
}
- if ( (daemon == events[i].data.ptr) ||
- (daemon->accept_pending) )
+ if (daemon == events[i].data.ptr)
{
- /* run 'accept' until it fails or we are not allowed to take
- on more connections */
- series_length = 0;
- while (MHD_YES == MHD_accept_connection (daemon))
- {
- if ( (daemon->connections < daemon->connection_limit) &&
- (series_length < 128) &&
- (! daemon->at_limit) )
- series_length++;
- else
- {
- /* Use the 'accept_pending' flag to remember that we stopped
- for resource limits, not because we drained accept() */
- daemon->accept_pending = true;
- break;
- }
- }
+ unsigned int series_length = 0;
+ /* Run 'accept' until it fails or daemon at limit of connections.
+ * Do not accept more then 10 connections at once. The rest will
+ * be accepted on next turn (level trigger is used for listen
+ * socket). */
+ while ( (MHD_YES == MHD_accept_connection (daemon)) &&
+ (series_length < 10) &&
+ (daemon->connections < daemon->connection_limit) &&
+ (! daemon->at_limit) )
+ series_length++;
continue;
}
/* this is an event relating to a 'normal' connection,
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
@@ -1405,13 +1405,6 @@ struct MHD_Daemon
*/
int listen_socket_in_epoll;
- /**
- * true if we have more incoming connections to be accepted from
- * the last event-loop iteration (and might not be triggered for
- * those explicitly anymore), false if we drained the queue.
- */
- bool accept_pending;
-
#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT)
/**
* File descriptor associated with the #run_epoll_for_upgrade() loop.