aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-27 15:35:58 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-27 22:11:55 +0300
commit7ad7452c190fe04cf843ccd530e44e6ced803992 (patch)
tree25ab1e66471356d2600fe3c9891f28ac39758c3f
parent4ebe2aa5f995d4cbf45c63d277ad1653ffca7725 (diff)
downloadlibmicrohttpd-7ad7452c190fe04cf843ccd530e44e6ced803992.tar.gz
libmicrohttpd-7ad7452c190fe04cf843ccd530e44e6ced803992.zip
Added new function MHD_get_timeout64()
The same functionally as MHD_get_timeout(), but with standard type uint64_t
-rw-r--r--src/include/microhttpd.h43
-rw-r--r--src/microhttpd/daemon.c64
2 files changed, 94 insertions, 13 deletions
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 06ca6964..3c2ad376 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -96,7 +96,7 @@ extern "C"
96 * they are parsed as decimal numbers. 96 * they are parsed as decimal numbers.
97 * Example: 0x01093001 = 1.9.30-1. 97 * Example: 0x01093001 = 1.9.30-1.
98 */ 98 */
99#define MHD_VERSION 0x00097507 99#define MHD_VERSION 0x00097508
100 100
101/* If generic headers don't work on your platform, include headers 101/* If generic headers don't work on your platform, include headers
102 which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 102 which define 'va_list', 'size_t', 'ssize_t', 'intptr_t',
@@ -2909,8 +2909,8 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon,
2909 * 2909 *
2910 * In practice, if #MHD_YES is returned then #MHD_run() (or 2910 * In practice, if #MHD_YES is returned then #MHD_run() (or
2911 * #MHD_run_from_select()) must be called not later than @a timeout 2911 * #MHD_run_from_select()) must be called not later than @a timeout
2912 * millisecond even if not activity is detected on sockets by 2912 * millisecond even if no activity is detected on sockets by sockets
2913 * sockets polling function. 2913 * polling function.
2914 * 2914 *
2915 * @param daemon daemon to query for timeout 2915 * @param daemon daemon to query for timeout
2916 * @param timeout set to the timeout (in milliseconds) 2916 * @param timeout set to the timeout (in milliseconds)
@@ -2924,6 +2924,43 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
2924 2924
2925 2925
2926/** 2926/**
2927 * Obtain timeout value for external polling function for this daemon.
2928 *
2929 * This function set value to the amount of milliseconds for which polling
2930 * function (`select()`, `poll()` or epoll) should at most block, not the
2931 * timeout value set for connections.
2932 *
2933 * Any "external" sockets polling function must be called with the timeout
2934 * value provided by this function. Smaller timeout values can be used for
2935 * polling function if it is required for any reason, but using larger
2936 * timeout value or no timeout (indefinite timeout) when this function
2937 * return #MHD_YES will break MHD processing logic and result in "hung"
2938 * connections with data pending in network buffers and other problems.
2939 *
2940 * It is important to always use this function when "external" polling is
2941 * used. If this function returns #MHD_YES then #MHD_run() (or
2942 * #MHD_run_from_select()) must be called right after return from polling
2943 * function, regardless of the states of MHD fds.
2944 *
2945 * In practice, if #MHD_YES is returned then #MHD_run() (or
2946 * #MHD_run_from_select()) must be called not later than @a timeout
2947 * millisecond even if no activity is detected on sockets by sockets
2948 * polling function.
2949 *
2950 * @param daemon daemon to query for timeout
2951 * @param timeout64 the pointer to the variable to be set to the
2952 * timeout (in milliseconds)
2953 * @return #MHD_YES if timeout value has been set,
2954 * #MHD_NO if timeouts are not used and no data processing is pending.
2955 * @note Available since #MHD_VERSION 0x00097508
2956 * @ingroup event
2957 */
2958_MHD_EXTERN enum MHD_Result
2959MHD_get_timeout64 (struct MHD_Daemon *daemon,
2960 uint64_t *timeout);
2961
2962
2963/**
2927 * Run webserver operations (without blocking unless in client callbacks). 2964 * Run webserver operations (without blocking unless in client callbacks).
2928 * 2965 *
2929 * This method should be called by clients in combination with 2966 * This method should be called by clients in combination with
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 1ec58e06..98999491 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2027,7 +2027,7 @@ thread_main_handle_connection (void *data)
2027#endif /* (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC */ 2027#endif /* (SIZEOF_UINT64_T - 2) >= SIZEOF_STRUCT_TIMEVAL_TV_SEC */
2028 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) mseconds_left / 1000; 2028 tv.tv_sec = (_MHD_TIMEVAL_TV_SEC_TYPE) mseconds_left / 1000;
2029 2029
2030 tv.tv_usec = ((uint16_t) (mseconds_left % 1000)) * 1000; 2030 tv.tv_usec = ((uint16_t) (mseconds_left % 1000)) * ((int32_t) 1000);
2031 tvp = &tv; 2031 tvp = &tv;
2032 } 2032 }
2033 else 2033 else
@@ -3917,6 +3917,56 @@ _MHD_EXTERN enum MHD_Result
3917MHD_get_timeout (struct MHD_Daemon *daemon, 3917MHD_get_timeout (struct MHD_Daemon *daemon,
3918 MHD_UNSIGNED_LONG_LONG *timeout) 3918 MHD_UNSIGNED_LONG_LONG *timeout)
3919{ 3919{
3920 uint64_t t64;
3921 if (MHD_NO == MHD_get_timeout64 (daemon, &t64))
3922 return MHD_NO;
3923
3924#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
3925 if (ULLONG_MAX <= t64)
3926 *timeout = ULLONG_MAX;
3927 else
3928#endif /* SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG */
3929 *timeout = (MHD_UNSIGNED_LONG_LONG) t64;
3930 return MHD_YES;
3931}
3932
3933
3934/**
3935 * Obtain timeout value for external polling function for this daemon.
3936 *
3937 * This function set value to the amount of milliseconds for which polling
3938 * function (`select()`, `poll()` or epoll) should at most block, not the
3939 * timeout value set for connections.
3940 *
3941 * Any "external" sockets polling function must be called with the timeout
3942 * value provided by this function. Smaller timeout values can be used for
3943 * polling function if it is required for any reason, but using larger
3944 * timeout value or no timeout (indefinite timeout) when this function
3945 * return #MHD_YES will break MHD processing logic and result in "hung"
3946 * connections with data pending in network buffers and other problems.
3947 *
3948 * It is important to always use this function when "external" polling is
3949 * used. If this function returns #MHD_YES then #MHD_run() (or
3950 * #MHD_run_from_select()) must be called right after return from polling
3951 * function, regardless of the states of MHD fds.
3952 *
3953 * In practice, if #MHD_YES is returned then #MHD_run() (or
3954 * #MHD_run_from_select()) must be called not later than @a timeout
3955 * millisecond even if not activity is detected on sockets by
3956 * sockets polling function.
3957 *
3958 * @param daemon daemon to query for timeout
3959 * @param timeout64 the pointer to the variable to be set to the
3960 * timeout (in milliseconds)
3961 * @return #MHD_YES if timeout value has been set,
3962 * #MHD_NO if timeouts are not used and no data processing is pending.
3963 * @note Available since #MHD_VERSION 0x00097508
3964 * @ingroup event
3965 */
3966_MHD_EXTERN enum MHD_Result
3967MHD_get_timeout64 (struct MHD_Daemon *daemon,
3968 uint64_t *timeout64)
3969{
3920 uint64_t earliest_deadline; 3970 uint64_t earliest_deadline;
3921 struct MHD_Connection *pos; 3971 struct MHD_Connection *pos;
3922 struct MHD_Connection *earliest_tmot_conn; /**< the connection with earliest timeout */ 3972 struct MHD_Connection *earliest_tmot_conn; /**< the connection with earliest timeout */
@@ -3937,7 +3987,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3937 if (daemon->data_already_pending) 3987 if (daemon->data_already_pending)
3938 { 3988 {
3939 /* Some data already waiting to be processed. */ 3989 /* Some data already waiting to be processed. */
3940 *timeout = 0; 3990 *timeout64 = 0;
3941 return MHD_YES; 3991 return MHD_YES;
3942 } 3992 }
3943#ifdef EPOLL_SUPPORT 3993#ifdef EPOLL_SUPPORT
@@ -3949,7 +3999,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3949 ) ) 3999 ) )
3950 { 4000 {
3951 /* Some connection(s) already have some data pending. */ 4001 /* Some connection(s) already have some data pending. */
3952 *timeout = 0; 4002 *timeout64 = 0;
3953 return MHD_YES; 4003 return MHD_YES;
3954 } 4004 }
3955#endif /* EPOLL_SUPPORT */ 4005#endif /* EPOLL_SUPPORT */
@@ -3981,13 +4031,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon,
3981 4031
3982 if (NULL != earliest_tmot_conn) 4032 if (NULL != earliest_tmot_conn)
3983 { 4033 {
3984 const uint64_t mssecond_left = connection_get_wait (earliest_tmot_conn); 4034 *timeout64 = connection_get_wait (earliest_tmot_conn);
3985#if SIZEOF_UINT64_T > SIZEOF_UNSIGNED_LONG_LONG
3986 if (mssecond_left > ULLONG_MAX)
3987 *timeout = ULLONG_MAX;
3988 else
3989#endif /* UINT64 != ULLONG_MAX */
3990 *timeout = (unsigned long long) mssecond_left;
3991 return MHD_YES; 4035 return MHD_YES;
3992 } 4036 }
3993 return MHD_NO; 4037 return MHD_NO;