From eac34ec36f32b6faafe0f3570ad8a342170f7417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20R=C5=B1tschl=C3=A9?= Date: Sun, 10 Aug 2025 08:49:02 +0200 Subject: [PATCH] refactor: consolidate loop init between sslh-select and sslh-ev --- processes.c | 9 ++++++++- processes.h | 1 + sslh-ev.c | 7 ++----- sslh-select.c | 7 ++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/processes.c b/processes.c index 82afd59..972c061 100644 --- a/processes.c +++ b/processes.c @@ -113,6 +113,13 @@ struct connection* cnx_accept_process(struct loop_info* fd_info, struct listen_e return cnx; } - +void loop_init(struct loop_info* loop) +{ + memset(loop, 0, sizeof(*loop)); + loop->collection = collection_init(0); + loop->probing_list = gap_init(0); + udp_init(loop); + tcp_init(); +} diff --git a/processes.h b/processes.h index b3c1ce8..57d604f 100644 --- a/processes.h +++ b/processes.h @@ -30,6 +30,7 @@ void cnx_read_process(struct loop_info* fd_info, int fd); struct connection* cnx_accept_process(struct loop_info* fd_info, struct listen_endpoint* listen_socket); int tidy_connection(struct connection *cnx, struct loop_info* fd_info); +void loop_init(struct loop_info* loop); /* These must be declared in the loop handler, sslh-ev or sslh-select */ diff --git a/sslh-ev.c b/sslh-ev.c index 8498d2a..3e2a4b9 100644 --- a/sslh-ev.c +++ b/sslh-ev.c @@ -131,13 +131,10 @@ static void cnx_accept_cb(EV_P_ ev_io *w, int revents) void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen) { - struct loop_info ev_info = {0}; + struct loop_info ev_info; loop = EV_DEFAULT; - ev_info.collection = collection_init(0); - ev_info.probing_list = gap_init(0); - udp_init(&ev_info); - tcp_init(); + loop_init(&ev_info); watchers_init(&ev_info.watchers, listen_sockets, num_addr_listen); ev_set_userdata(EV_A_ &ev_info); diff --git a/sslh-select.c b/sslh-select.c index 5ee679e..2b87c6d 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -124,15 +124,12 @@ static int fd_out_of_range(int fd) { */ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen) { - struct loop_info fd_info = {0}; + struct loop_info fd_info; fd_set readfds, writefds; /* working read and write fd sets */ struct timeval tv; int i, res; - fd_info.num_probing = 0; - fd_info.probing_list = gap_init(0); - udp_init(&fd_info); - tcp_init(); + loop_init(&fd_info); watchers_init(&fd_info.watchers, listen_sockets, num_addr_listen);