diff options
-rw-r--r-- | src/include/microhttpd.h | 52 | ||||
-rw-r--r-- | 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" | |||
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 0x00097509 | 99 | #define MHD_VERSION 0x00097510 |
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', |
@@ -2903,7 +2903,8 @@ MHD_get_fdset2 (struct MHD_Daemon *daemon, | |||
2903 | * connections with data pending in network buffers and other problems. | 2903 | * connections with data pending in network buffers and other problems. |
2904 | * | 2904 | * |
2905 | * It is important to always use this function (or #MHD_get_timeout64(), | 2905 | * It is important to always use this function (or #MHD_get_timeout64(), |
2906 | * #MHD_get_timeout64s() functions) when "external" polling is used. | 2906 | * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" |
2907 | * polling is used. | ||
2907 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) | 2908 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) |
2908 | * must be called right after return from polling function, regardless of | 2909 | * must be called right after return from polling function, regardless of |
2909 | * the states of MHD FDs. | 2910 | * the states of MHD FDs. |
@@ -2939,7 +2940,8 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
2939 | * connections with data pending in network buffers and other problems. | 2940 | * connections with data pending in network buffers and other problems. |
2940 | * | 2941 | * |
2941 | * It is important to always use this function (or #MHD_get_timeout(), | 2942 | * It is important to always use this function (or #MHD_get_timeout(), |
2942 | * #MHD_get_timeout64s() functions) when "external" polling is used. | 2943 | * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" |
2944 | * polling is used. | ||
2943 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) | 2945 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) |
2944 | * must be called right after return from polling function, regardless of | 2946 | * must be called right after return from polling function, regardless of |
2945 | * the states of MHD FDs. | 2947 | * the states of MHD FDs. |
@@ -2978,7 +2980,8 @@ MHD_get_timeout64 (struct MHD_Daemon *daemon, | |||
2978 | * network buffers and other problems. | 2980 | * network buffers and other problems. |
2979 | * | 2981 | * |
2980 | * It is important to always use this function (or #MHD_get_timeout(), | 2982 | * It is important to always use this function (or #MHD_get_timeout(), |
2981 | * #MHD_get_timeout64() functions) when "external" polling is used. | 2983 | * #MHD_get_timeout64(), #MHD_get_timeout_i() functions) when "external" |
2984 | * polling is used. | ||
2982 | * If this function returns non-negative value then #MHD_run() (or | 2985 | * If this function returns non-negative value then #MHD_run() (or |
2983 | * #MHD_run_from_select()) must be called right after return from polling | 2986 | * #MHD_run_from_select()) must be called right after return from polling |
2984 | * function, regardless of the states of MHD FDs. | 2987 | * function, regardless of the states of MHD FDs. |
@@ -3002,6 +3005,47 @@ MHD_get_timeout64s (struct MHD_Daemon *daemon); | |||
3002 | 3005 | ||
3003 | 3006 | ||
3004 | /** | 3007 | /** |
3008 | * Obtain timeout value for external polling function for this daemon. | ||
3009 | * | ||
3010 | * This function set value to the amount of milliseconds for which polling | ||
3011 | * function (`select()`, `poll()` or epoll) should at most block, not the | ||
3012 | * timeout value set for connections. | ||
3013 | * | ||
3014 | * Any "external" sockets polling function must be called with the timeout | ||
3015 | * value provided by this function (if returned value is non-negative). | ||
3016 | * Smaller timeout values can be used for polling function if it is required | ||
3017 | * for any reason, but using larger timeout value or no timeout (indefinite | ||
3018 | * timeout) when this function returns non-negative value will break MHD | ||
3019 | * processing logic and result in "hung" connections with data pending in | ||
3020 | * network buffers and other problems. | ||
3021 | * | ||
3022 | * It is important to always use this function (or #MHD_get_timeout(), | ||
3023 | * #MHD_get_timeout64(), #MHD_get_timeout64s() functions) when "external" | ||
3024 | * polling is used. | ||
3025 | * If this function returns non-negative value then #MHD_run() (or | ||
3026 | * #MHD_run_from_select()) must be called right after return from polling | ||
3027 | * function, regardless of the states of MHD FDs. | ||
3028 | * | ||
3029 | * In practice, if zero or positive value is returned then #MHD_run() (or | ||
3030 | * #MHD_run_from_select()) must be called not later than returned amount of | ||
3031 | * millisecond even if no activity is detected on sockets by sockets | ||
3032 | * polling function. | ||
3033 | * | ||
3034 | * @param daemon the daemon to query for timeout | ||
3035 | * @return -1 if connections' timeouts are not set and no data processing | ||
3036 | * is pending, so external polling function may wait for sockets | ||
3037 | * activity for indefinite amount of time, | ||
3038 | * otherwise returned value is the the maximum amount of millisecond | ||
3039 | * (capped at INT_MAX) that external polling function must wait | ||
3040 | * for the activity of FDs. | ||
3041 | * @note Available since #MHD_VERSION 0x00097510 | ||
3042 | * @ingroup event | ||
3043 | */ | ||
3044 | _MHD_EXTERN int | ||
3045 | MHD_get_timeout_i (struct MHD_Daemon *daemon); | ||
3046 | |||
3047 | |||
3048 | /** | ||
3005 | * Run webserver operations (without blocking unless in client callbacks). | 3049 | * Run webserver operations (without blocking unless in client callbacks). |
3006 | * | 3050 | * |
3007 | * This method should be called by clients in combination with | 3051 | * This method should be called by clients in combination with |
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) | |||
3896 | * connections with data pending in network buffers and other problems. | 3896 | * connections with data pending in network buffers and other problems. |
3897 | * | 3897 | * |
3898 | * It is important to always use this function (or #MHD_get_timeout64(), | 3898 | * It is important to always use this function (or #MHD_get_timeout64(), |
3899 | * #MHD_get_timeout64s() functions) when "external" polling is used. | 3899 | * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" |
3900 | * polling is used. | ||
3900 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) | 3901 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) |
3901 | * must be called right after return from polling function, regardless of | 3902 | * must be called right after return from polling function, regardless of |
3902 | * the states of MHD FDs. | 3903 | * the states of MHD FDs. |
@@ -3947,7 +3948,8 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
3947 | * connections with data pending in network buffers and other problems. | 3948 | * connections with data pending in network buffers and other problems. |
3948 | * | 3949 | * |
3949 | * It is important to always use this function (or #MHD_get_timeout(), | 3950 | * It is important to always use this function (or #MHD_get_timeout(), |
3950 | * #MHD_get_timeout64s() functions) when "external" polling is used. | 3951 | * #MHD_get_timeout64s(), #MHD_get_timeout_i() functions) when "external" |
3952 | * polling is used. | ||
3951 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) | 3953 | * If this function returns #MHD_YES then #MHD_run() (or #MHD_run_from_select()) |
3952 | * must be called right after return from polling function, regardless of | 3954 | * must be called right after return from polling function, regardless of |
3953 | * the states of MHD FDs. | 3955 | * the states of MHD FDs. |
@@ -4058,7 +4060,8 @@ MHD_get_timeout64 (struct MHD_Daemon *daemon, | |||
4058 | * network buffers and other problems. | 4060 | * network buffers and other problems. |
4059 | * | 4061 | * |
4060 | * It is important to always use this function (or #MHD_get_timeout(), | 4062 | * It is important to always use this function (or #MHD_get_timeout(), |
4061 | * #MHD_get_timeout64() functions) when "external" polling is used. | 4063 | * #MHD_get_timeout64(), #MHD_get_timeout_i() functions) when "external" |
4064 | * polling is used. | ||
4062 | * If this function returns non-negative value then #MHD_run() (or | 4065 | * If this function returns non-negative value then #MHD_run() (or |
4063 | * #MHD_run_from_select()) must be called right after return from polling | 4066 | * #MHD_run_from_select()) must be called right after return from polling |
4064 | * function, regardless of the states of MHD FDs. | 4067 | * function, regardless of the states of MHD FDs. |
@@ -4093,6 +4096,59 @@ MHD_get_timeout64s (struct MHD_Daemon *daemon) | |||
4093 | 4096 | ||
4094 | 4097 | ||
4095 | /** | 4098 | /** |
4099 | * Obtain timeout value for external polling function for this daemon. | ||
4100 | * | ||
4101 | * This function set value to the amount of milliseconds for which polling | ||
4102 | * function (`select()`, `poll()` or epoll) should at most block, not the | ||
4103 | * timeout value set for connections. | ||
4104 | * | ||
4105 | * Any "external" sockets polling function must be called with the timeout | ||
4106 | * value provided by this function (if returned value is non-negative). | ||
4107 | * Smaller timeout values can be used for polling function if it is required | ||
4108 | * for any reason, but using larger timeout value or no timeout (indefinite | ||
4109 | * timeout) when this function returns non-negative value will break MHD | ||
4110 | * processing logic and result in "hung" connections with data pending in | ||
4111 | * network buffers and other problems. | ||
4112 | * | ||
4113 | * It is important to always use this function (or #MHD_get_timeout(), | ||
4114 | * #MHD_get_timeout64(), #MHD_get_timeout64s() functions) when "external" | ||
4115 | * polling is used. | ||
4116 | * If this function returns non-negative value then #MHD_run() (or | ||
4117 | * #MHD_run_from_select()) must be called right after return from polling | ||
4118 | * function, regardless of the states of MHD FDs. | ||
4119 | * | ||
4120 | * In practice, if zero or positive value is returned then #MHD_run() (or | ||
4121 | * #MHD_run_from_select()) must be called not later than returned amount of | ||
4122 | * millisecond even if no activity is detected on sockets by sockets | ||
4123 | * polling function. | ||
4124 | * @remark To be called only from thread that process | ||
4125 | * daemon's select()/poll()/etc. | ||
4126 | * | ||
4127 | * @param daemon the daemon to query for timeout | ||
4128 | * @return -1 if connections' timeouts are not set and no data processing | ||
4129 | * is pending, so external polling function may wait for sockets | ||
4130 | * activity for indefinite amount of time, | ||
4131 | * otherwise returned value is the the maximum amount of millisecond | ||
4132 | * (capped at INT_MAX) that external polling function must wait | ||
4133 | * for the activity of FDs. | ||
4134 | * @note Available since #MHD_VERSION 0x00097510 | ||
4135 | * @ingroup event | ||
4136 | */ | ||
4137 | _MHD_EXTERN int | ||
4138 | MHD_get_timeout_i (struct MHD_Daemon *daemon) | ||
4139 | { | ||
4140 | #if SIZEOF_INT >= SIZEOF_INT64_T | ||
4141 | return MHD_get_timeout64s (daemon); | ||
4142 | #else /* SIZEOF_INT < SIZEOF_INT64_T */ | ||
4143 | const int64_t to64 = MHD_get_timeout64s (daemon); | ||
4144 | if (INT_MAX >= to64) | ||
4145 | return to64; | ||
4146 | return INT_MAX; | ||
4147 | #endif /* SIZEOF_INT < SIZEOF_INT64_T */ | ||
4148 | } | ||
4149 | |||
4150 | |||
4151 | /** | ||
4096 | * Obtain timeout value for polling function for this daemon. | 4152 | * Obtain timeout value for polling function for this daemon. |
4097 | * @remark To be called only from the thread that processes | 4153 | * @remark To be called only from the thread that processes |
4098 | * daemon's select()/poll()/etc. | 4154 | * daemon's select()/poll()/etc. |