diff options
Diffstat (limited to 'src/microhttpd/connection.c')
-rw-r--r-- | src/microhttpd/connection.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index bcb3f934..de81f08a 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -3487,17 +3487,17 @@ MHD_update_last_activity_ (struct MHD_Connection *connection) | |||
3487 | { | 3487 | { |
3488 | struct MHD_Daemon *daemon = connection->daemon; | 3488 | struct MHD_Daemon *daemon = connection->daemon; |
3489 | 3489 | ||
3490 | if (0 == connection->connection_timeout) | 3490 | if (0 == connection->connection_timeout_ms) |
3491 | return; /* Skip update of activity for connections | 3491 | return; /* Skip update of activity for connections |
3492 | without timeout timer. */ | 3492 | without timeout timer. */ |
3493 | if (connection->suspended) | 3493 | if (connection->suspended) |
3494 | return; /* no activity on suspended connections */ | 3494 | return; /* no activity on suspended connections */ |
3495 | 3495 | ||
3496 | connection->last_activity = MHD_monotonic_sec_counter (); | 3496 | connection->last_activity = MHD_monotonic_msec_counter (); |
3497 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 3497 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
3498 | return; /* each connection has personal timeout */ | 3498 | return; /* each connection has personal timeout */ |
3499 | 3499 | ||
3500 | if (connection->connection_timeout != daemon->connection_timeout) | 3500 | if (connection->connection_timeout_ms != daemon->connection_timeout_ms) |
3501 | return; /* custom timeout, no need to move it in "normal" DLL */ | 3501 | return; /* custom timeout, no need to move it in "normal" DLL */ |
3502 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 3502 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
3503 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 3503 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
@@ -4011,7 +4011,7 @@ cleanup_connection (struct MHD_Connection *connection) | |||
4011 | { | 4011 | { |
4012 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 4012 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
4013 | { | 4013 | { |
4014 | if (connection->connection_timeout == daemon->connection_timeout) | 4014 | if (connection->connection_timeout_ms == daemon->connection_timeout_ms) |
4015 | XDLL_remove (daemon->normal_timeout_head, | 4015 | XDLL_remove (daemon->normal_timeout_head, |
4016 | daemon->normal_timeout_tail, | 4016 | daemon->normal_timeout_tail, |
4017 | connection); | 4017 | connection); |
@@ -4584,11 +4584,13 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
4584 | } | 4584 | } |
4585 | if (! connection->suspended) | 4585 | if (! connection->suspended) |
4586 | { | 4586 | { |
4587 | time_t timeout; | 4587 | uint64_t timeout; |
4588 | timeout = connection->connection_timeout; | 4588 | timeout = connection->connection_timeout_ms; |
4589 | /* Keep the next lines in sync with #MHD_get_timeout() to avoid | ||
4590 | * undesired side-effects like busy-waiting. */ | ||
4589 | if ( (0 != timeout) && | 4591 | if ( (0 != timeout) && |
4590 | (timeout <= (MHD_monotonic_sec_counter () | 4592 | (timeout < (MHD_monotonic_msec_counter () |
4591 | - connection->last_activity)) ) | 4593 | - connection->last_activity)) ) |
4592 | { | 4594 | { |
4593 | MHD_connection_close_ (connection, | 4595 | MHD_connection_close_ (connection, |
4594 | MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); | 4596 | MHD_REQUEST_TERMINATED_TIMEOUT_REACHED); |
@@ -4719,8 +4721,8 @@ MHD_get_connection_info (struct MHD_Connection *connection, | |||
4719 | connection->suspended_dummy = connection->suspended ? MHD_YES : MHD_NO; | 4721 | connection->suspended_dummy = connection->suspended ? MHD_YES : MHD_NO; |
4720 | return (const union MHD_ConnectionInfo *) &connection->suspended_dummy; | 4722 | return (const union MHD_ConnectionInfo *) &connection->suspended_dummy; |
4721 | case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT: | 4723 | case MHD_CONNECTION_INFO_CONNECTION_TIMEOUT: |
4722 | connection->connection_timeout_dummy = (unsigned | 4724 | connection->connection_timeout_dummy = |
4723 | int) connection->connection_timeout; | 4725 | (unsigned int) connection->connection_timeout_ms * 1000; |
4724 | return (const union MHD_ConnectionInfo *) &connection-> | 4726 | return (const union MHD_ConnectionInfo *) &connection-> |
4725 | connection_timeout_dummy; | 4727 | connection_timeout_dummy; |
4726 | case MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE: | 4728 | case MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE: |
@@ -4759,15 +4761,15 @@ MHD_set_connection_option (struct MHD_Connection *connection, | |||
4759 | switch (option) | 4761 | switch (option) |
4760 | { | 4762 | { |
4761 | case MHD_CONNECTION_OPTION_TIMEOUT: | 4763 | case MHD_CONNECTION_OPTION_TIMEOUT: |
4762 | if (0 == connection->connection_timeout) | 4764 | if (0 == connection->connection_timeout_ms) |
4763 | connection->last_activity = MHD_monotonic_sec_counter (); | 4765 | connection->last_activity = MHD_monotonic_msec_counter (); |
4764 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) | 4766 | #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) |
4765 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); | 4767 | MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); |
4766 | #endif | 4768 | #endif |
4767 | if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 4769 | if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
4768 | (! connection->suspended) ) | 4770 | (! connection->suspended) ) |
4769 | { | 4771 | { |
4770 | if (connection->connection_timeout == daemon->connection_timeout) | 4772 | if (connection->connection_timeout_ms == daemon->connection_timeout_ms) |
4771 | XDLL_remove (daemon->normal_timeout_head, | 4773 | XDLL_remove (daemon->normal_timeout_head, |
4772 | daemon->normal_timeout_tail, | 4774 | daemon->normal_timeout_tail, |
4773 | connection); | 4775 | connection); |
@@ -4777,13 +4779,29 @@ MHD_set_connection_option (struct MHD_Connection *connection, | |||
4777 | connection); | 4779 | connection); |
4778 | } | 4780 | } |
4779 | va_start (ap, option); | 4781 | va_start (ap, option); |
4780 | connection->connection_timeout = va_arg (ap, | 4782 | connection->connection_timeout_ms = va_arg (ap, |
4781 | unsigned int); | 4783 | unsigned int); |
4782 | va_end (ap); | 4784 | va_end (ap); |
4785 | #if (0 == (UINT64_MAX + 0)) || ((UINT_MAX + 0) >= (UINT64_MAX + 0)) | ||
4786 | if ((UINT64_MAX / 2000 - 1) < connection->connection_timeout_ms) | ||
4787 | { | ||
4788 | #ifdef HAVE_MESSAGES | ||
4789 | MHD_DLOG (connection->daemon, | ||
4790 | _ ("The specified connection timeout (" PRIu64 ") is too " \ | ||
4791 | "large. Maximum allowed value (" PRIu64 ") will be used " \ | ||
4792 | "instead.\n"), | ||
4793 | connection->connection_timeout_ms, | ||
4794 | (UINT64_MAX / 2000 - 1)); | ||
4795 | #endif | ||
4796 | connection->connection_timeout_ms = UINT64_MAX / 2000 - 1; | ||
4797 | } | ||
4798 | else | ||
4799 | #endif /* UINTMAX_MAX >= UINT64_MAX */ | ||
4800 | connection->connection_timeout_ms *= 1000; | ||
4783 | if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 4801 | if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && |
4784 | (! connection->suspended) ) | 4802 | (! connection->suspended) ) |
4785 | { | 4803 | { |
4786 | if (connection->connection_timeout == daemon->connection_timeout) | 4804 | if (connection->connection_timeout_ms == daemon->connection_timeout_ms) |
4787 | XDLL_insert (daemon->normal_timeout_head, | 4805 | XDLL_insert (daemon->normal_timeout_head, |
4788 | daemon->normal_timeout_tail, | 4806 | daemon->normal_timeout_tail, |
4789 | connection); | 4807 | connection); |