libmicrohttpd

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

commit 1125f7dd9fc64b0577f7ba6b41567c7e4b2e5e88
parent 0c2f60904d6c8137d806580c48426be513c52ebf
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed,  7 Oct 2020 21:26:33 +0300

MHD_epoll: handle timeout before data processing
Connection should not timeout if it gets new data while processing data on other connections

Diffstat:
Msrc/microhttpd/daemon.c | 52+++++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -4592,6 +4592,33 @@ MHD_epoll (struct MHD_Daemon *daemon, series_length++; } + /* Handle timed-out connections; we need to do this here + as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, + as the other event loops do. As timeouts do not get an explicit + event, we need to find those connections that might have timed out + here. + + Connections with custom timeouts must all be looked at, as we + do not bother to sort that (presumably very short) list. */ + prev = daemon->manual_timeout_tail; + while (NULL != (pos = prev)) + { + prev = pos->prevX; + MHD_connection_handle_idle (pos); + } + /* Connections with the default timeout are sorted by prepending + them to the head of the list whenever we touch the connection; + thus it suffices to iterate from the tail until the first + connection is NOT timed out */ + prev = daemon->normal_timeout_tail; + while (NULL != (pos = prev)) + { + prev = pos->prevX; + MHD_connection_handle_idle (pos); + if (MHD_CONNECTION_CLOSED != pos->state) + break; /* sorted by timeout, no need to visit the rest! */ + } + #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) if (run_upgraded || (NULL != daemon->eready_urh_head)) run_epoll_for_upgrade (daemon); @@ -4624,31 +4651,6 @@ MHD_epoll (struct MHD_Daemon *daemon, } } - /* Finally, handle timed-out connections; we need to do this here - as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, - as the other event loops do. As timeouts do not get an explicit - event, we need to find those connections that might have timed out - here. - - Connections with custom timeouts must all be looked at, as we - do not bother to sort that (presumably very short) list. */prev = daemon->manual_timeout_tail; - while (NULL != (pos = prev)) - { - prev = pos->prevX; - MHD_connection_handle_idle (pos); - } - /* Connections with the default timeout are sorted by prepending - them to the head of the list whenever we touch the connection; - thus it suffices to iterate from the tail until the first - connection is NOT timed out */ - prev = daemon->normal_timeout_tail; - while (NULL != (pos = prev)) - { - prev = pos->prevX; - MHD_connection_handle_idle (pos); - if (MHD_CONNECTION_CLOSED != pos->state) - break; /* sorted by timeout, no need to visit the rest! */ - } return MHD_YES; }