commit e5c2647ba4dc0b1a7a11457f7e19a296fb633ba6
parent a2fb6811f5c325dff2e82373ff9ae6034860ea72
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Fri, 30 May 2025 09:50:47 +0200
Daemon struct: renamed timeout member
Diffstat:
7 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/src/include/d_options.rec b/src/include/d_options.rec
@@ -258,8 +258,10 @@ Comment: Control ALPN for TLS connection.
Name: DEFAULT_TIMEOUT
Value: 160
Comment: Specify inactivity timeout for connection.
-+ When no activity for specified time on connection, it is closed automatically.
++ When no activity for specified time on connection, it is closed
++ automatically.
+ Use zero for no timeout, which is also the (unsafe!) default.
++ Very large values (years) can be silently truncated to smaller values.
Argument1: unsigned int timeout
Description1: the in seconds, zero for no timeout
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
@@ -4289,8 +4289,10 @@ MHD_D_OPTION_NO_ALPN (
/**
* Specify inactivity timeout for connection.
- * When no activity for specified time on connection, it is closed automatically.
+ * When no activity for specified time on connection, it is closed
+ * automatically.
* Use zero for no timeout, which is also the (unsafe!) default.
+ * Very large values (years) can be silently truncated to smaller values.
* @param timeout the in seconds, zero for no timeout
* @return structure with the requested setting
*/
diff --git a/src/include/microhttpd2_generated_daemon_options.h b/src/include/microhttpd2_generated_daemon_options.h
@@ -150,8 +150,10 @@ Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
/**
* Specify inactivity timeout for connection.
- * When no activity for specified time on connection, it is closed automatically.
+ * When no activity for specified time on connection, it is closed
+ * automatically.
* Use zero for no timeout, which is also the (unsafe!) default.
+ * Very large values (years) can be silently truncated to smaller values.
*/
MHD_D_O_DEFAULT_TIMEOUT = 160
,
@@ -1136,8 +1138,10 @@ Works only when #MHD_D_OPTION_BIND_PORT() or #MHD_D_OPTION_BIND_SA() are used.
MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_RESTORE_WARN_AGGR_DYN_INIT_
/**
* Specify inactivity timeout for connection.
- * When no activity for specified time on connection, it is closed automatically.
+ * When no activity for specified time on connection, it is closed
+ * automatically.
* Use zero for no timeout, which is also the (unsafe!) default.
+ * Very large values (years) can be silently truncated to smaller values.
* @param timeout the in seconds, zero for no timeout
* @return structure with the requested setting
*/
@@ -1911,8 +1915,10 @@ MHD_D_OPTION_NO_ALPN (
/**
* Specify inactivity timeout for connection.
- * When no activity for specified time on connection, it is closed automatically.
+ * When no activity for specified time on connection, it is closed
+ * automatically.
* Use zero for no timeout, which is also the (unsafe!) default.
+ * Very large values (years) can be silently truncated to smaller values.
* @param timeout the in seconds, zero for no timeout
* @return structure with the requested setting
*/
diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c
@@ -270,7 +270,7 @@ 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;
+ c->connection_timeout_ms = daemon->conns.cfg.timeout_ms;
c->event_loop_info = MHD_EVENT_LOOP_INFO_RECV;
#ifdef MHD_SUPPORT_HTTPS
diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c
@@ -133,6 +133,8 @@ MHD_FN_MUST_CHECK_RESULT_ enum MHD_StatusCode
daemon_set_basic_settings (struct MHD_Daemon *restrict d,
struct DaemonOptions *restrict s)
{
+ static const uint_fast64_t max_timeout_ms_value =
+ ((uint_fast64_t) ~((uint_fast64_t) 0)) / 8;
d->req_cfg.strictness = s->protocol_strict_level.v_sl;
#ifdef MHD_SUPPORT_COOKIES
@@ -141,6 +143,12 @@ daemon_set_basic_settings (struct MHD_Daemon *restrict d,
d->req_cfg.suppress_date = (MHD_NO != s->suppress_date_header);
+ d->conns.cfg.timeout_ms = ((uint_fast64_t) s->default_timeout) * 1000u;
+ if (d->conns.cfg.timeout_ms / 1000u != s->default_timeout)
+ d->conns.cfg.timeout_ms = max_timeout_ms_value;
+ else if (max_timeout_ms_value < d->conns.cfg.timeout_ms)
+ d->conns.cfg.timeout_ms = max_timeout_ms_value;
+
return MHD_SC_OK;
}
diff --git a/src/mhd2/mhd_daemon.h b/src/mhd2/mhd_daemon.h
@@ -884,9 +884,9 @@ struct mhd_DaemonConnectionsSettings
unsigned int count_limit;
/**
- * Connection's default timeout value (in seconds)
+ * Connection's default timeout value (in milliseconds)
*/
- unsigned int timeout;
+ uint_fast64_t timeout_ms;
/**
* Connection's memory pool size
diff --git a/src/mhd2/stream_funcs.c b/src/mhd2/stream_funcs.c
@@ -687,7 +687,7 @@ mhd_stream_update_activity_mark (struct MHD_Connection *restrict c)
if (mhd_D_HAS_THR_PER_CONN (d))
return; /* each connection has personal timeout */
- if (c->connection_timeout_ms != d->conns.cfg.timeout)
+ if (c->connection_timeout_ms != d->conns.cfg.timeout_ms)
return; /* custom timeout, no need to move it in "normal" DLL */
/* move connection to head of timeout list (by remove + add operation) */
@@ -715,7 +715,7 @@ mhd_stream_resumed_activity_mark (struct MHD_Connection *restrict c)
if (mhd_D_HAS_THR_PER_CONN (d))
return; /* each connection has personal timeout */
- if (c->connection_timeout_ms == d->conns.cfg.timeout)
+ if (c->connection_timeout_ms == d->conns.cfg.timeout_ms)
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);
@@ -729,7 +729,7 @@ mhd_conn_remove_from_timeout_lists (struct MHD_Connection *restrict c)
if (mhd_D_HAS_THR_PER_CONN (c->daemon))
return;
- if (c->connection_timeout_ms == c->daemon->conns.cfg.timeout)
+ if (c->connection_timeout_ms == c->daemon->conns.cfg.timeout_ms)
mhd_DLINKEDL_DEL_D (&(c->daemon->conns.def_timeout), \
c, by_timeout);
else