[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 03/05: Added new function MHD_get_timeout_i()
From: |
gnunet |
Subject: |
[libmicrohttpd] 03/05: Added new function MHD_get_timeout_i() |
Date: |
Thu, 28 Apr 2022 18:09:46 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit c6eae238be6357a7e0b77298a0cdada4c63e80bc
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Thu Apr 28 16:59:19 2022 +0300
Added new function MHD_get_timeout_i()
This function is useful for direct in in poll() or epoll_wait().
---
src/include/microhttpd.h | 52 ++++++++++++++++++++++++++++++++++++----
src/microhttpd/daemon.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 107 insertions(+), 7 deletions(-)
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).
*
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 4e349206..65529b3c 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -3896,7 +3896,8 @@ MHD_cleanup_connections (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.
@@ -3947,7 +3948,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.
@@ -4058,7 +4060,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.
@@ -4092,6 +4095,59 @@ 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.
+ * @remark To be called only from thread that process
+ * daemon's select()/poll()/etc.
+ *
+ * @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)
+{
+#if SIZEOF_INT >= SIZEOF_INT64_T
+ return MHD_get_timeout64s (daemon);
+#else /* SIZEOF_INT < SIZEOF_INT64_T */
+ const int64_t to64 = MHD_get_timeout64s (daemon);
+ if (INT_MAX >= to64)
+ return to64;
+ return INT_MAX;
+#endif /* SIZEOF_INT < SIZEOF_INT64_T */
+}
+
+
/**
* Obtain timeout value for polling function for this daemon.
* @remark To be called only from the thread that processes
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.