libmicrohttpd

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

commit 2590e0e8913bdf8cfa19113cb42d9738413c9d70
parent c1a1826e8ebb8814fb26e2d255235f6527297f00
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Thu, 12 May 2022 15:47:50 +0300

MHD_set_connection_option(): reduced lock scope

Improved handling of setting the new connection timeout. Log function
is not called with lock held. Simplified logic, completely avoided
locking in thread-per-connection mode

Diffstat:
Msrc/microhttpd/connection.c | 57+++++++++++++++++++++++++++------------------------------
1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -5107,21 +5107,6 @@ MHD_set_connection_option (struct MHD_Connection *connection, case MHD_CONNECTION_OPTION_TIMEOUT: if (0 == connection->connection_timeout_ms) connection->last_activity = MHD_monotonic_msec_counter (); -#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) - MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); -#endif - if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (! connection->suspended) ) - { - if (connection->connection_timeout_ms == daemon->connection_timeout_ms) - XDLL_remove (daemon->normal_timeout_head, - daemon->normal_timeout_tail, - connection); - else - XDLL_remove (daemon->manual_timeout_head, - daemon->manual_timeout_tail, - connection); - } va_start (ap, option); ui_val = va_arg (ap, unsigned int); va_end (ap); @@ -5138,24 +5123,36 @@ MHD_set_connection_option (struct MHD_Connection *connection, #endif ui_val = UINT64_MAX / 4000 - 1; } - else #endif /* (SIZEOF_UINT64_T - 2) <= SIZEOF_UNSIGNED_INT */ - connection->connection_timeout_ms = ui_val * 1000; - if ( (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && - (! connection->suspended) ) + if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { - if (connection->connection_timeout_ms == daemon->connection_timeout_ms) - XDLL_insert (daemon->normal_timeout_head, - daemon->normal_timeout_tail, - connection); - else - XDLL_insert (daemon->manual_timeout_head, - daemon->manual_timeout_tail, - connection); - } -#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) - MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); +#if defined(MHD_USE_THREADS) + MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); #endif + if (! connection->suspended) + { + if (connection->connection_timeout_ms == daemon->connection_timeout_ms) + XDLL_remove (daemon->normal_timeout_head, + daemon->normal_timeout_tail, + connection); + else + XDLL_remove (daemon->manual_timeout_head, + daemon->manual_timeout_tail, + connection); + connection->connection_timeout_ms = ui_val * 1000; + if (connection->connection_timeout_ms == daemon->connection_timeout_ms) + XDLL_insert (daemon->normal_timeout_head, + daemon->normal_timeout_tail, + connection); + else + XDLL_insert (daemon->manual_timeout_head, + daemon->manual_timeout_tail, + connection); + } +#if defined(MHD_USE_THREADS) + MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); +#endif + } return MHD_YES; default: return MHD_NO;