libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 0c2f60904d6c8137d806580c48426be513c52ebf
parent 9665bdd0a83f2a8792a4bd324dea927940b3b236
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed,  7 Oct 2020 20:23:53 +0300

MHD_epoll: separate epoll results processing from external data processing

Diffstat:
Msrc/microhttpd/daemon.c | 30++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -4373,6 +4373,7 @@ MHD_epoll (struct MHD_Daemon *daemon, #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) bool run_upgraded = false; #endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ + bool need_to_accept; if (-1 == daemon->epoll_fd) return MHD_NO; /* we're down! */ @@ -4474,6 +4475,7 @@ MHD_epoll (struct MHD_Daemon *daemon, * signaled in epoll mode by non-empty eready DLL. */ daemon->data_already_pending = false; + need_to_accept = false; /* drain 'epoll' event queue; need to iterate as we get at most MAX_EVENTS in one system call here; in practice this should pretty much mean only one round, but better an extra loop here @@ -4525,18 +4527,7 @@ MHD_epoll (struct MHD_Daemon *daemon, /* Check for error conditions on listen socket. */ /* FIXME: Initiate MHD_quiesce_daemon() to prevent busy waiting? */ if (0 == (events[i].events & (EPOLLERR | EPOLLHUP))) - { - 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_NO != MHD_accept_connection (daemon)) && - (series_length < 10) && - (daemon->connections < daemon->connection_limit) && - (! daemon->at_limit) ) - series_length++; - } + need_to_accept = true; continue; } /* this is an event relating to a 'normal' connection, @@ -4586,6 +4577,21 @@ MHD_epoll (struct MHD_Daemon *daemon, } } + if (need_to_accept) + { + 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_NO != MHD_accept_connection (daemon)) && + (series_length < 10) && + (daemon->connections < daemon->connection_limit) && + (! daemon->at_limit) ) + series_length++; + } + #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) if (run_upgraded || (NULL != daemon->eready_urh_head)) run_epoll_for_upgrade (daemon);