commit c16ece71b53bcc8cbc968632168c7d4f33f3c663
parent 1de3ba7eecf97bf78c40f347286df6bbd7c8a070
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sat, 28 Feb 2026 19:37:28 +0100
Added dedicated union for events in MHD_Connection
Diffstat:
4 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/src/mhd2/daemon_event_update.c b/src/mhd2/daemon_event_update.c
@@ -158,9 +158,9 @@ MHD_daemon_event_update (
struct MHD_Connection *const c = ((struct MHD_Connection *) ecb_cntx);
unsigned int err_flag;
- mhd_assert (MHD_FD_STATE_NONE != c->extr_event.reg_for);
+ mhd_assert (MHD_FD_STATE_NONE != c->events.extrn.reg_for);
- unneeded_event = (0 != ((~((unsigned int) c->extr_event.reg_for))
+ unneeded_event = (0 != ((~((unsigned int) c->events.extrn.reg_for))
& ((unsigned int) fd_current_state)));
/* Preserve connection's "error flag" */
@@ -170,7 +170,7 @@ MHD_daemon_event_update (
c->sk.ready =
(enum mhd_SocketNetState)
(err_flag | (((unsigned int) fd_current_state)
- & ((unsigned int) c->extr_event.reg_for)));
+ & ((unsigned int) c->events.extrn.reg_for)));
}
break;
}
diff --git a/src/mhd2/events_process.c b/src/mhd2/events_process.c
@@ -820,16 +820,16 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d)
if (is_conn_excluded_from_http_comm (c))
{
- if (NULL != c->extr_event.app_cntx)
+ if (NULL != c->events.extrn.app_cntx)
{
/* De-register the connection socket FD */
- c->extr_event.app_cntx =
+ c->events.extrn.app_cntx =
mhd_daemon_extr_event_reg (d,
c->sk.fd,
MHD_FD_STATE_NONE,
- c->extr_event.app_cntx,
+ c->events.extrn.app_cntx,
(struct MHD_EventUpdateContext *) c);
- if (NULL != c->extr_event.app_cntx)
+ if (NULL != c->events.extrn.app_cntx)
mhd_log_extr_event_dereg_failed (d);
}
continue;
@@ -844,28 +844,28 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d)
| MHD_EVENT_LOOP_INFO_SEND)));
mhd_assert ((! edge_trigg) || \
- (MHD_FD_STATE_RECV_SEND_EXCEPT == c->extr_event.reg_for) || \
- (NULL == c->extr_event.app_cntx));
+ (MHD_FD_STATE_RECV_SEND_EXCEPT == c->events.extrn.reg_for) || \
+ (NULL == c->events.extrn.app_cntx));
- if ((NULL == c->extr_event.app_cntx) ||
+ if ((NULL == c->events.extrn.app_cntx) ||
rereg_all ||
- (! edge_trigg && (watch_for != c->extr_event.reg_for)))
+ (! edge_trigg && (watch_for != c->events.extrn.reg_for)))
{
/* (Re-)register the connection socket FD */
- c->extr_event.app_cntx =
+ c->events.extrn.app_cntx =
mhd_daemon_extr_event_reg (d,
c->sk.fd,
watch_for,
- c->extr_event.app_cntx,
+ c->events.extrn.app_cntx,
(struct MHD_EventUpdateContext *) c);
- if (NULL == c->extr_event.app_cntx)
+ if (NULL == c->events.extrn.app_cntx)
{
mhd_conn_start_closing_ext_event_failed (c);
mhd_conn_pre_clean (c);
mhd_conn_remove_from_daemon (c);
mhd_conn_close_final (c);
}
- c->extr_event.reg_for = watch_for;
+ c->events.extrn.reg_for = watch_for;
}
}
diff --git a/src/mhd2/mhd_connection.h b/src/mhd2/mhd_connection.h
@@ -541,6 +541,17 @@ struct mhd_ConnExtrEvents
enum MHD_FdState reg_for;
};
+/**
+ * The connection events data
+ */
+union mhd_ConnEvents
+{
+ /**
+ * The connection's external event data
+ */
+ struct mhd_ConnExtrEvents extrn;
+};
+
/**
* The helper struct for the connections list
@@ -623,9 +634,11 @@ struct MHD_Connection
struct mhd_ConnSocket sk;
/**
- * The connection's external event data
+ * The connection's events
+ *
+ * The active member depends on daemon's mode
*/
- struct mhd_ConnExtrEvents extr_event;
+ union mhd_ConnEvents events;
#ifdef MHD_SUPPORT_HTTPS
/**
diff --git a/src/mhd2/stream_funcs.c b/src/mhd2/stream_funcs.c
@@ -1039,15 +1039,15 @@ mhd_conn_pre_clean_part1 (struct MHD_Connection *restrict c)
if (mhd_WM_INT_HAS_EXT_EVENTS (c->daemon->wmode_int))
{
struct MHD_Daemon *const d = c->daemon;
- if (NULL != c->extr_event.app_cntx)
+ if (NULL != c->events.extrn.app_cntx)
{
- c->extr_event.app_cntx =
+ c->events.extrn.app_cntx =
mhd_daemon_extr_event_reg (d,
c->sk.fd,
MHD_FD_STATE_NONE,
- c->extr_event.app_cntx,
+ c->events.extrn.app_cntx,
(struct MHD_EventUpdateContext *) c);
- if (NULL != c->extr_event.app_cntx)
+ if (NULL != c->events.extrn.app_cntx)
mhd_log_extr_event_dereg_failed (d);
}
}