commit 76f6a033eb760b65bb055ad517cfd6cd3c04934e
parent 11a54be055cb52babacb81a759c524aba480f3ce
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Wed, 24 Dec 2025 20:55:22 +0100
Added connection timeout initialisation function
Diffstat:
3 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/src/mhd2/conn_timeout.c b/src/mhd2/conn_timeout.c
@@ -50,6 +50,8 @@
#include "mhd_mono_clock.h"
+#include "mhd_dlinked_list.h"
+
#include "mhd_daemon.h"
#include "mhd_connection.h"
@@ -103,6 +105,37 @@ mhd_conn_is_timeout_expired (struct MHD_Connection *restrict c)
MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
+mhd_conn_init_activity_timeout (struct MHD_Connection *restrict c,
+ uint_fast32_t timeout)
+{
+ struct MHD_Daemon *const restrict d = c->daemon;
+
+#if defined(MHD_SUPPORT_THREADS)
+ mhd_assert (! mhd_D_HAS_WORKERS (d));
+#endif /* MHD_SUPPORT_THREADS */
+
+ mhd_assert (! c->suspended);
+
+ c->connection_timeout_ms = timeout;
+
+ if (0 != timeout)
+ c->last_activity = mhd_monotonic_msec_counter (); // TODO: Get and use time value one time per round
+
+ if (mhd_D_HAS_THR_PER_CONN (d))
+ return;
+
+ if (timeout == d->conns.cfg.timeout_milsec)
+ mhd_DLINKEDL_INS_FIRST_D (&(d->conns.def_timeout),
+ c,
+ by_timeout);
+ else
+ mhd_DLINKEDL_INS_FIRST_D (&(d->conns.cust_timeout),
+ c,
+ by_timeout);
+}
+
+
+MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void
mhd_conn_update_activity_mark (struct MHD_Connection *restrict c)
{
struct MHD_Daemon *const restrict d = c->daemon;
diff --git a/src/mhd2/conn_timeout.h b/src/mhd2/conn_timeout.h
@@ -48,6 +48,7 @@
#include "mhd_sys_options.h"
#include "sys_bool_type.h"
+#include "sys_base_types.h"
struct MHD_Connection; /* Forward declaration */
@@ -64,6 +65,18 @@ MHD_FN_PAR_NONNULL_ALL_;
/**
+ * Initialise activity timeout data.
+ * Add connection to the timeouts list if needed; set activity mark, if needed.
+ * @param c the connection to initialise
+ * @param timeout the connection timeout value to use
+ */
+MHD_INTERNAL void
+mhd_conn_init_activity_timeout (struct MHD_Connection *restrict c,
+ uint_fast32_t timeout)
+MHD_FN_PAR_NONNULL_ALL_;
+
+
+/**
* Update last activity mark to the current time.
* @param c the connection to update
*/
diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c
@@ -87,6 +87,7 @@
#include "response_from.h"
#include "response_destroy.h"
+#include "conn_timeout.h"
#include "conn_mark_ready.h"
#ifdef MHD_SUPPORT_HTTP2
@@ -316,7 +317,6 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
mhd_thread_handle_ID_set_invalid (&c->tid);
#endif /* MHD_SUPPORT_THREADS */
c->daemon = daemon;
- c->connection_timeout_ms = daemon->conns.cfg.timeout_milsec;
c->event_loop_info = MHD_EVENT_LOOP_INFO_RECV;
#ifdef MHD_SUPPORT_HTTPS
@@ -344,8 +344,6 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon,
if (MHD_SC_OK == ret)
{
- if (0 != c->connection_timeout_ms)
- c->last_activity = mhd_monotonic_msec_counter ();
*conn_out = c;
return MHD_SC_OK; /* Success exit point */
@@ -413,9 +411,9 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon,
daemon->conns.block_new =
(daemon->conns.count >= daemon->conns.cfg.count_limit);
mhd_DLINKEDL_INS_LAST (&(daemon->conns), connection, all_conn);
- if (! mhd_D_HAS_THR_PER_CONN (daemon))
- mhd_DLINKEDL_INS_FIRST_D (&(daemon->conns.def_timeout), \
- connection, by_timeout);
+
+ mhd_conn_init_activity_timeout (connection,
+ daemon->conns.cfg.timeout_milsec);
connection_set_http_layer_init_state (connection);
connection_set_initial_state (connection);