aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--src/microhttpd/daemon.c49
2 files changed, 40 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac
index a6af4004..a500efe7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1437,6 +1437,7 @@ struct timeval test_var;
1437) 1437)
1438AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec], 1438AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec],
1439 [The size of `tv_sec' member of `struct timeval', as computed by sizeof]) 1439 [The size of `tv_sec' member of `struct timeval', as computed by sizeof])
1440AC_CHECK_SIZEOF([int64_t], [], [[#include <stdint.h>]])
1440AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]]) 1441AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]])
1441AC_CHECK_SIZEOF([int], [], [[#include <stdint.h>]]) 1442AC_CHECK_SIZEOF([int], [], [[#include <stdint.h>]])
1442AC_CHECK_SIZEOF([unsigned int], [], [[#include <stdint.h>]]) 1443AC_CHECK_SIZEOF([unsigned int], [], [[#include <stdint.h>]])
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 98999491..dec72581 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -4048,22 +4048,51 @@ MHD_get_timeout64 (struct MHD_Daemon *daemon,
4048 * ignored if set to '-1' 4048 * ignored if set to '-1'
4049 * @return timeout value in milliseconds or -1 if no timeout is expected. 4049 * @return timeout value in milliseconds or -1 if no timeout is expected.
4050 */ 4050 */
4051static int 4051static int64_t
4052get_timeout_millisec_ (struct MHD_Daemon *daemon, 4052get_timeout_millisec_ (struct MHD_Daemon *daemon,
4053 int32_t max_timeout) 4053 int32_t max_timeout)
4054{ 4054{
4055 MHD_UNSIGNED_LONG_LONG ulltimeout; 4055 uint64_t d_timeout;
4056 mhd_assert (0 <= max_timeout || -1 == max_timeout);
4056 if (0 == max_timeout) 4057 if (0 == max_timeout)
4057 return 0; 4058 return 0;
4058 4059
4059 if (MHD_NO == MHD_get_timeout (daemon, &ulltimeout)) 4060 if (MHD_NO == MHD_get_timeout64 (daemon, &d_timeout))
4060 return (INT_MAX < max_timeout) ? INT_MAX : (int) max_timeout; 4061 return max_timeout;
4062
4063 if ((0 < max_timeout) && ((uint64_t) max_timeout < d_timeout))
4064 return max_timeout;
4065
4066 if (INT64_MAX < d_timeout)
4067 return INT64_MAX;
4068
4069 return (int64_t) d_timeout;
4070}
4061 4071
4062 if ( (0 > max_timeout) ||
4063 ((uint32_t) max_timeout > ulltimeout) )
4064 return (INT_MAX < ulltimeout) ? INT_MAX : (int) ulltimeout;
4065 4072
4066 return (INT_MAX < max_timeout) ? INT_MAX : (int) max_timeout; 4073/**
4074 * Obtain timeout value for polling function for this daemon.
4075 * @remark To be called only from the thread that processes
4076 * daemon's select()/poll()/etc.
4077 *
4078 * @param daemon the daemon to query for timeout
4079 * @param max_timeout the maximum return value (in milliseconds),
4080 * ignored if set to '-1'
4081 * @return timeout value in milliseconds, capped to INT_MAX, or
4082 * -1 if no timeout is expected.
4083 */
4084static int
4085get_timeout_millisec_int (struct MHD_Daemon *daemon,
4086 int32_t max_timeout)
4087{
4088 int64_t res;
4089
4090 res = get_timeout_millisec_ (daemon, max_timeout);
4091#if SIZEOF_INT < SIZEOF_INT64_T
4092 if (INT_MAX <= res)
4093 return INT_MAX;
4094#endif /* SIZEOF_INT < SIZEOF_INT64_T */
4095 return (int) res;
4067} 4096}
4068 4097
4069 4098
@@ -4505,7 +4534,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
4505 poll_server++; 4534 poll_server++;
4506 } 4535 }
4507 4536
4508 timeout = get_timeout_millisec_ (daemon, millisec); 4537 timeout = get_timeout_millisec_int (daemon, millisec);
4509 4538
4510 i = 0; 4539 i = 0;
4511 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev) 4540 for (pos = daemon->connections_tail; NULL != pos; pos = pos->prev)
@@ -5047,7 +5076,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
5047 (MHD_NO != resume_suspended_connections (daemon)) ) 5076 (MHD_NO != resume_suspended_connections (daemon)) )
5048 millisec = 0; 5077 millisec = 0;
5049 5078
5050 timeout_ms = get_timeout_millisec_ (daemon, millisec); 5079 timeout_ms = get_timeout_millisec_int (daemon, millisec);
5051 5080
5052 /* Reset. New value will be set when connections are processed. */ 5081 /* Reset. New value will be set when connections are processed. */
5053 /* Note: Used mostly for uniformity here as same situation is 5082 /* Note: Used mostly for uniformity here as same situation is