diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-04-05 23:21:59 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2017-04-05 23:21:59 +0300 |
commit | 8851d88e40a33bb942165c45d4e9d439038106a9 (patch) | |
tree | d102a6e22f3f7f81f12abc489e1358e2822665f1 | |
parent | 076cbfbe0b1fb1535d2718f9cfc0d839a44d691e (diff) | |
download | libmicrohttpd-8851d88e40a33bb942165c45d4e9d439038106a9.tar.gz libmicrohttpd-8851d88e40a33bb942165c45d4e9d439038106a9.zip |
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.
-rw-r--r-- | src/microhttpd/connection.c | 5 | ||||
-rw-r--r-- | src/microhttpd/connection_https.c | 2 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 21 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 9 |
4 files changed, 27 insertions, 10 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 0b6ce3bd..70c7268e 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -3245,7 +3245,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
3245 | } | 3245 | } |
3246 | if (! connection->suspended) | 3246 | if (! connection->suspended) |
3247 | { | 3247 | { |
3248 | unsigned int timeout; | 3248 | time_t timeout; |
3249 | timeout = connection->connection_timeout; | 3249 | timeout = connection->connection_timeout; |
3250 | if ( (0 != timeout) && | 3250 | if ( (0 != timeout) && |
3251 | (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)) ) | 3251 | (timeout < (MHD_monotonic_sec_counter() - connection->last_activity)) ) |
@@ -3377,7 +3377,8 @@ MHD_get_connection_info (struct MHD_Connection *connection, | |||
3377 | case MHD_CONNECTION_INFO_CONNECTION_SUSPENDED: | 3377 | case MHD_CONNECTION_INFO_CONNECTION_SUSPENDED: |
3378 | return (const union MHD_ConnectionInfo *) &connection->suspended; | 3378 | return (const union MHD_ConnectionInfo *) &connection->suspended; |
3379 | case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT: | 3379 | case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT: |
3380 | return (const union MHD_ConnectionInfo *) &connection->connection_timeout; | 3380 | connection->connection_timeout_dummy = connection->connection_timeout; |
3381 | return (const union MHD_ConnectionInfo *) &connection->connection_timeout_dummy; | ||
3381 | default: | 3382 | default: |
3382 | return NULL; | 3383 | return NULL; |
3383 | }; | 3384 | }; |
diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c index fe197f1d..9b441a9a 100644 --- 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) | |||
132 | static int | 132 | static int |
133 | MHD_tls_connection_handle_idle (struct MHD_Connection *connection) | 133 | MHD_tls_connection_handle_idle (struct MHD_Connection *connection) |
134 | { | 134 | { |
135 | unsigned int timeout; | 135 | time_t timeout; |
136 | 136 | ||
137 | #if DEBUG_STATES | 137 | #if DEBUG_STATES |
138 | MHD_DLOG (connection->daemon, | 138 | MHD_DLOG (connection->daemon, |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 8a9df765..b92d5534 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -1803,7 +1803,7 @@ thread_main_handle_connection (void *data) | |||
1803 | while ( (! daemon->shutdown) && | 1803 | while ( (! daemon->shutdown) && |
1804 | (MHD_CONNECTION_CLOSED != con->state) ) | 1804 | (MHD_CONNECTION_CLOSED != con->state) ) |
1805 | { | 1805 | { |
1806 | const unsigned int timeout = daemon->connection_timeout; | 1806 | const time_t timeout = daemon->connection_timeout; |
1807 | #ifdef UPGRADE_SUPPORT | 1807 | #ifdef UPGRADE_SUPPORT |
1808 | struct MHD_UpgradeResponseHandle * const urh = con->urh; | 1808 | struct MHD_UpgradeResponseHandle * const urh = con->urh; |
1809 | #else /* ! UPGRADE_SUPPORT */ | 1809 | #else /* ! UPGRADE_SUPPORT */ |
@@ -3276,7 +3276,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
3276 | if (0 != pos->connection_timeout) | 3276 | if (0 != pos->connection_timeout) |
3277 | { | 3277 | { |
3278 | if ( (! have_timeout) || | 3278 | if ( (! have_timeout) || |
3279 | (earliest_deadline > pos->last_activity + pos->connection_timeout) ) | 3279 | (earliest_deadline - pos->last_activity > pos->connection_timeout) ) |
3280 | earliest_deadline = pos->last_activity + pos->connection_timeout; | 3280 | earliest_deadline = pos->last_activity + pos->connection_timeout; |
3281 | have_timeout = true; | 3281 | have_timeout = true; |
3282 | } | 3282 | } |
@@ -3287,7 +3287,7 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
3287 | (0 != pos->connection_timeout) ) | 3287 | (0 != pos->connection_timeout) ) |
3288 | { | 3288 | { |
3289 | if ( (! have_timeout) || | 3289 | if ( (! have_timeout) || |
3290 | (earliest_deadline > pos->last_activity + pos->connection_timeout) ) | 3290 | (earliest_deadline - pos->connection_timeout > pos->last_activity) ) |
3291 | earliest_deadline = pos->last_activity + pos->connection_timeout; | 3291 | earliest_deadline = pos->last_activity + pos->connection_timeout; |
3292 | have_timeout = true; | 3292 | have_timeout = true; |
3293 | } | 3293 | } |
@@ -4766,6 +4766,7 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
4766 | enum MHD_OPTION opt; | 4766 | enum MHD_OPTION opt; |
4767 | struct MHD_OptionItem *oa; | 4767 | struct MHD_OptionItem *oa; |
4768 | unsigned int i; | 4768 | unsigned int i; |
4769 | unsigned int uv; | ||
4769 | #ifdef HTTPS_SUPPORT | 4770 | #ifdef HTTPS_SUPPORT |
4770 | int ret; | 4771 | int ret; |
4771 | const char *pstr; | 4772 | const char *pstr; |
@@ -4788,8 +4789,18 @@ parse_options_va (struct MHD_Daemon *daemon, | |||
4788 | unsigned int); | 4789 | unsigned int); |
4789 | break; | 4790 | break; |
4790 | case MHD_OPTION_CONNECTION_TIMEOUT: | 4791 | case MHD_OPTION_CONNECTION_TIMEOUT: |
4791 | daemon->connection_timeout = va_arg (ap, | 4792 | uv = va_arg (ap, |
4792 | unsigned int); | 4793 | unsigned int); |
4794 | if (TIME_T_MAX < uv) | ||
4795 | { | ||
4796 | #ifdef HAVE_MESSAGES | ||
4797 | MHD_DLOG (daemon, | ||
4798 | _("Warning: Too large timeout value, ignored.\n")); | ||
4799 | #endif | ||
4800 | daemon->connection_timeout = 0; | ||
4801 | } | ||
4802 | else | ||
4803 | daemon->connection_timeout = (time_t)uv; | ||
4793 | break; | 4804 | break; |
4794 | case MHD_OPTION_NOTIFY_COMPLETED: | 4805 | case MHD_OPTION_NOTIFY_COMPLETED: |
4795 | daemon->notify_completed = va_arg (ap, | 4806 | daemon->notify_completed = va_arg (ap, |
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 1b9df892..9ced47c1 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -789,7 +789,12 @@ struct MHD_Connection | |||
789 | * After how many seconds of inactivity should | 789 | * After how many seconds of inactivity should |
790 | * this connection time out? Zero for no timeout. | 790 | * this connection time out? Zero for no timeout. |
791 | */ | 791 | */ |
792 | unsigned int connection_timeout; | 792 | time_t connection_timeout; |
793 | |||
794 | /** | ||
795 | * Special member to be returned by #MHD_get_connection_info() | ||
796 | */ | ||
797 | unsigned int connection_timeout_dummy; | ||
793 | 798 | ||
794 | /** | 799 | /** |
795 | * Did we ever call the "default_handler" on this connection? (this | 800 | * Did we ever call the "default_handler" on this connection? (this |
@@ -1517,7 +1522,7 @@ struct MHD_Daemon | |||
1517 | * After how many seconds of inactivity should | 1522 | * After how many seconds of inactivity should |
1518 | * connections time out? Zero for no timeout. | 1523 | * connections time out? Zero for no timeout. |
1519 | */ | 1524 | */ |
1520 | unsigned int connection_timeout; | 1525 | time_t connection_timeout; |
1521 | 1526 | ||
1522 | /** | 1527 | /** |
1523 | * Maximum number of connections per IP, or 0 for | 1528 | * Maximum number of connections per IP, or 0 for |