From c6eae238be6357a7e0b77298a0cdada4c63e80bc Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Thu, 28 Apr 2022 16:59:19 +0300 Subject: Added new function MHD_get_timeout_i() This function is useful for direct in in poll() or epoll_wait(). --- src/include/microhttpd.h | 52 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) (limited to 'src/include/microhttpd.h') diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index 0563e907..8f89eba0 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h @@ -96,7 +96,7 @@ extern "C" * they are parsed as decimal numbers. * Example: 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00097509 +#define MHD_VERSION 0x00097510 /* If generic headers don't work on your platform, include headers which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', @@ -2903,7 +2903,8 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon, * connections with data pending in network buffers and other problems. * * It is important to always use this function (or #MHD_get_timeout64(), - * #MHD_get_timeout64s() functions) when "external" polling is used. + * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" + * polling is used. * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) * must be called right after return from polling function, regardless of * the states of MHD FDs. @@ -2939,7 +2940,8 @@ MHD_get_timeout (struct MHD_Daemon *daemon, * connections with data pending in network buffers and other problems. * * It is important to always use this function (or #MHD_get_timeout(), - * #MHD_get_timeout64s() functions) when "external" polling is used. + * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" + * polling is used. * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) * must be called right after return from polling function, regardless of * the states of MHD FDs. @@ -2978,7 +2980,8 @@ MHD_get_timeout64 (struct MHD_Daemon *daemon, * network buffers and other problems. * * It is important to always use this function (or #MHD_get_timeout(), - * #MHD_get_timeout64() functions) when "external" polling is used. + * #MHD_get_timeout64(), #MHD_get_timeout_i() functions) when "external" + * polling is used. * If this function returns non-negative value then #MHD_run() (or * #MHD_run_from_select()) must be called right after return from polling * function, regardless of the states of MHD FDs. @@ -3001,6 +3004,47 @@ _MHD_EXTERN int64_t MHD_get_timeout64s (struct MHD_Daemon *daemon); +/** + * Obtain timeout value for external polling function for this daemon. + * + * This function set value to the amount of milliseconds for which polling + * function (`select()`, `poll()` or epoll) should at most block, not the + * timeout value set for connections. + * + * Any "external" sockets polling function must be called with the timeout + * value provided by this function (if returned value is non-negative). + * Smaller timeout values can be used for polling function if it is required + * for any reason, but using larger timeout value or no timeout (indefinite + * timeout) when this function returns non-negative value will break MHD + * processing logic and result in "hung" connections with data pending in + * network buffers and other problems. + * + * It is important to always use this function (or #MHD_get_timeout(), + * #MHD_get_timeout64(), #MHD_get_timeout64s() functions) when "external" + * polling is used. + * If this function returns non-negative value then #MHD_run() (or + * #MHD_run_from_select()) must be called right after return from polling + * function, regardless of the states of MHD FDs. + * + * In practice, if zero or positive value is returned then #MHD_run() (or + * #MHD_run_from_select()) must be called not later than returned amount of + * millisecond even if no activity is detected on sockets by sockets + * polling function. + * + * @param daemon the daemon to query for timeout + * @return -1 if connections' timeouts are not set and no data processing + * is pending, so external polling function may wait for sockets + * activity for indefinite amount of time, + * otherwise returned value is the the maximum amount of millisecond + * (capped at INT_MAX) that external polling function must wait + * for the activity of FDs. + * @note Available since #MHD_VERSION 0x00097510 + * @ingroup event + */ +_MHD_EXTERN int +MHD_get_timeout_i (struct MHD_Daemon *daemon); + + /** * Run webserver operations (without blocking unless in client callbacks). * -- cgit v1.2.3