libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 8851d88e40a33bb942165c45d4e9d439038106a9
parent 076cbfbe0b1fb1535d2718f9cfc0d839a44d691e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed,  5 Apr 2017 23:21:59 +0300

Fixed hypothetical situation when timeout could be larger than possible to measure.
Fixed detecting real closest timeout deadline when value wraps upper limit.
Fixed compiler warnings.

Diffstat:
Msrc/microhttpd/connection.c | 5+++--
Msrc/microhttpd/connection_https.c | 2+-
Msrc/microhttpd/daemon.c | 21++++++++++++++++-----
Msrc/microhttpd/internal.h | 9+++++++--
4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -3245,7 +3245,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) } if (! connection->suspended) { - unsigned int timeout; + time_t timeout; timeout = connection->connection_timeout; if ( (0 != timeout) && (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)) ) @@ -3377,7 +3377,8 @@ MHD_get_connection_info (struct MHD_Connection *connection, case MHD_CONNECTION_INFO_CONNECTION_SUSPENDED: return (const union MHD_ConnectionInfo *) &connection->suspended; case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT: - return (const union MHD_ConnectionInfo *) &connection->connection_timeout; + connection->connection_timeout_dummy = connection->connection_timeout; + return (const union MHD_ConnectionInfo *) &connection->connection_timeout_dummy; default: return NULL; }; diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c @@ -132,7 +132,7 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection) static int MHD_tls_connection_handle_idle (struct MHD_Connection *connection) { - unsigned int timeout; + time_t timeout; #if DEBUG_STATES MHD_DLOG (connection->daemon, diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c @@ -1803,7 +1803,7 @@ thread_main_handle_connection (void *data) while ( (! daemon->shutdown) && (MHD_CONNECTION_CLOSED != con->state) ) { - const unsigned int timeout = daemon->connection_timeout; + const time_t timeout = daemon->connection_timeout; #ifdef UPGRADE_SUPPORT struct MHD_UpgradeResponseHandle * const urh = con->urh; #else /* ! UPGRADE_SUPPORT */ @@ -3276,7 +3276,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon, if (0 != pos->connection_timeout) { if ( (! have_timeout) || - (earliest_deadline > pos->last_activity + pos->connection_timeout) ) + (earliest_deadline - pos->last_activity > pos->connection_timeout) ) earliest_deadline = pos->last_activity + pos->connection_timeout; have_timeout = true; } @@ -3287,7 +3287,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon, (0 != pos->connection_timeout) ) { if ( (! have_timeout) || - (earliest_deadline > pos->last_activity + pos->connection_timeout) ) + (earliest_deadline - pos->connection_timeout > pos->last_activity) ) earliest_deadline = pos->last_activity + pos->connection_timeout; have_timeout = true; } @@ -4766,6 +4766,7 @@ parse_options_va (struct MHD_Daemon *daemon, enum MHD_OPTION opt; struct MHD_OptionItem *oa; unsigned int i; + unsigned int uv; #ifdef HTTPS_SUPPORT int ret; const char *pstr; @@ -4788,8 +4789,18 @@ parse_options_va (struct MHD_Daemon *daemon, unsigned int); break; case MHD_OPTION_CONNECTION_TIMEOUT: - daemon->connection_timeout = va_arg (ap, - unsigned int); + uv = va_arg (ap, + unsigned int); + if (TIME_T_MAX < uv) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (daemon, + _("Warning: Too large timeout value, ignored.\n")); +#endif + daemon->connection_timeout = 0; + } + else + daemon->connection_timeout = (time_t)uv; break; case MHD_OPTION_NOTIFY_COMPLETED: daemon->notify_completed = va_arg (ap, diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -789,7 +789,12 @@ struct MHD_Connection * After how many seconds of inactivity should * this connection time out? Zero for no timeout. */ - unsigned int connection_timeout; + time_t connection_timeout; + + /** + * Special member to be returned by #MHD_get_connection_info() + */ + unsigned int connection_timeout_dummy; /** * Did we ever call the "default_handler" on this connection? (this @@ -1517,7 +1522,7 @@ struct MHD_Daemon * After how many seconds of inactivity should * connections time out? Zero for no timeout. */ - unsigned int connection_timeout; + time_t connection_timeout; /** * Maximum number of connections per IP, or 0 for