diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-07 21:26:33 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2020-10-07 21:31:38 +0300 |
commit | 1125f7dd9fc64b0577f7ba6b41567c7e4b2e5e88 (patch) | |
tree | a947543356bf00bb31bc131780514adcbd4be861 | |
parent | 0c2f60904d6c8137d806580c48426be513c52ebf (diff) | |
download | libmicrohttpd-1125f7dd9fc64b0577f7ba6b41567c7e4b2e5e88.tar.gz libmicrohttpd-1125f7dd9fc64b0577f7ba6b41567c7e4b2e5e88.zip |
MHD_epoll: handle timeout before data processing
Connection should not timeout if it gets new data while processing data on other connections
-rw-r--r-- | src/microhttpd/daemon.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index f1c1350a..22b0a775 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -4592,6 +4592,33 @@ MHD_epoll (struct MHD_Daemon *daemon, | |||
4592 | series_length++; | 4592 | series_length++; |
4593 | } | 4593 | } |
4594 | 4594 | ||
4595 | /* Handle timed-out connections; we need to do this here | ||
4596 | as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, | ||
4597 | as the other event loops do. As timeouts do not get an explicit | ||
4598 | event, we need to find those connections that might have timed out | ||
4599 | here. | ||
4600 | |||
4601 | Connections with custom timeouts must all be looked at, as we | ||
4602 | do not bother to sort that (presumably very short) list. */ | ||
4603 | prev = daemon->manual_timeout_tail; | ||
4604 | while (NULL != (pos = prev)) | ||
4605 | { | ||
4606 | prev = pos->prevX; | ||
4607 | MHD_connection_handle_idle (pos); | ||
4608 | } | ||
4609 | /* Connections with the default timeout are sorted by prepending | ||
4610 | them to the head of the list whenever we touch the connection; | ||
4611 | thus it suffices to iterate from the tail until the first | ||
4612 | connection is NOT timed out */ | ||
4613 | prev = daemon->normal_timeout_tail; | ||
4614 | while (NULL != (pos = prev)) | ||
4615 | { | ||
4616 | prev = pos->prevX; | ||
4617 | MHD_connection_handle_idle (pos); | ||
4618 | if (MHD_CONNECTION_CLOSED != pos->state) | ||
4619 | break; /* sorted by timeout, no need to visit the rest! */ | ||
4620 | } | ||
4621 | |||
4595 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) | 4622 | #if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) |
4596 | if (run_upgraded || (NULL != daemon->eready_urh_head)) | 4623 | if (run_upgraded || (NULL != daemon->eready_urh_head)) |
4597 | run_epoll_for_upgrade (daemon); | 4624 | run_epoll_for_upgrade (daemon); |
@@ -4624,31 +4651,6 @@ MHD_epoll (struct MHD_Daemon *daemon, | |||
4624 | } | 4651 | } |
4625 | } | 4652 | } |
4626 | 4653 | ||
4627 | /* Finally, handle timed-out connections; we need to do this here | ||
4628 | as the epoll mechanism won't call the 'MHD_connection_handle_idle()' on everything, | ||
4629 | as the other event loops do. As timeouts do not get an explicit | ||
4630 | event, we need to find those connections that might have timed out | ||
4631 | here. | ||
4632 | |||
4633 | Connections with custom timeouts must all be looked at, as we | ||
4634 | do not bother to sort that (presumably very short) list. */prev = daemon->manual_timeout_tail; | ||
4635 | while (NULL != (pos = prev)) | ||
4636 | { | ||
4637 | prev = pos->prevX; | ||
4638 | MHD_connection_handle_idle (pos); | ||
4639 | } | ||
4640 | /* Connections with the default timeout are sorted by prepending | ||
4641 | them to the head of the list whenever we touch the connection; | ||
4642 | thus it suffices to iterate from the tail until the first | ||
4643 | connection is NOT timed out */ | ||
4644 | prev = daemon->normal_timeout_tail; | ||
4645 | while (NULL != (pos = prev)) | ||
4646 | { | ||
4647 | prev = pos->prevX; | ||
4648 | MHD_connection_handle_idle (pos); | ||
4649 | if (MHD_CONNECTION_CLOSED != pos->state) | ||
4650 | break; /* sorted by timeout, no need to visit the rest! */ | ||
4651 | } | ||
4652 | return MHD_YES; | 4654 | return MHD_YES; |
4653 | } | 4655 | } |
4654 | 4656 | ||