From 2c7659ec930277981b6333b5b3aff7840d11933c Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 18:51:51 +0100 Subject: Decouple config parsing from binding and worker spawning * Options are parsed now into a listener description list before binding them at once and starting the workers later * UDP workers can now be configured per connection * socket reuse is now done more sensibly, mcast sockets always reused * Hold-off logic after spawning udp workers removed --- tests/t_socket.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/t_socket.c b/tests/t_socket.c index bbc9e5e..8eef7fd 100644 --- a/tests/t_socket.c +++ b/tests/t_socket.c @@ -91,14 +91,14 @@ static void case_socket_options(void) { int udp, tcp; test_case("a bound udp socket is non blocking and serves both families"); - udp = socket_udp_bind(ip_any, 0); + udp = socket_udp_bind(ip_any, 0, SOCKET_EXCLUSIVE); CHECK(udp != -1); CHECK_INT(is_nonblocking(udp), 1); CHECK_INT(sock_flag(udp, IPPROTO_IPV6, IPV6_V6ONLY), 0); close(udp); test_case("a listening tcp socket is non blocking and serves both families"); - tcp = socket_tcp_listen(ip_any, 0); + tcp = socket_tcp_listen(ip_any, 0, SOCKET_EXCLUSIVE); CHECK(tcp != -1); CHECK_INT(is_nonblocking(tcp), 1); CHECK_INT(sock_flag(tcp, IPPROTO_IPV6, IPV6_V6ONLY), 0); @@ -106,24 +106,20 @@ static void case_socket_options(void) { } #ifdef SO_REUSEPORT -static void case_reuseport_is_opt_in(void) { +static void case_sharing_is_opt_in(void) { int s; - test_case("reuseport stays off unless the operator asks for it"); - g_socket_reuseport = 0; - s = socket_udp_bind(ip_loopback, 0); + test_case("an address is exclusive unless sharing is asked for"); + s = socket_udp_bind(ip_loopback, 0, SOCKET_EXCLUSIVE); CHECK(s != -1); CHECK_INT(sock_flag(s, SOL_SOCKET, SO_REUSEPORT), 0); close(s); - test_case("reuseport reaches the socket when it is asked for"); - g_socket_reuseport = 1; - s = socket_udp_bind(ip_loopback, 0); + test_case("and shared when it is"); + s = socket_udp_bind(ip_loopback, 0, SOCKET_SHARED); CHECK(s != -1); CHECK_INT(sock_flag(s, SOL_SOCKET, SO_REUSEPORT), 1); close(s); - - g_socket_reuseport = 0; } #endif @@ -135,7 +131,7 @@ static void case_udp_roundtrip(void) { int s; test_case("a datagram comes back with the sender's address and port"); - s = socket_udp_bind(ip_loopback, 0); + s = socket_udp_bind(ip_loopback, 0, SOCKET_EXCLUSIVE); CHECK(s != -1); bound_address(s, own_ip, &own_port); CHECK(own_port != 0); @@ -158,9 +154,9 @@ static void case_udp_v4mapped(void) { int receiver, sender; test_case("an IPv4 sender is reported in its v4 mapped form"); - receiver = socket_udp_bind(ip_v4_loopback, 0); + receiver = socket_udp_bind(ip_v4_loopback, 0, SOCKET_EXCLUSIVE); CHECK(receiver != -1); - sender = socket_udp_bind(ip_v4_loopback, 0); + sender = socket_udp_bind(ip_v4_loopback, 0, SOCKET_EXCLUSIVE); CHECK(sender != -1); bound_address(receiver, receiver_ip, &receiver_port); bound_address(sender, sender_ip, &sender_port); @@ -184,7 +180,7 @@ static void case_tcp_roundtrip(void) { int listener, client, accepted; test_case("a connection is accepted and carries the caller's address"); - listener = socket_tcp_listen(ip_loopback, 0); + listener = socket_tcp_listen(ip_loopback, 0, SOCKET_EXCLUSIVE); CHECK(listener != -1); bound_address(listener, listener_ip, &listener_port); CHECK(listener_port != 0); @@ -216,7 +212,7 @@ static void case_connect_refused(void) { test_case("a refused connection is reported by socket_is_connected"); /* Take a port, then drop it, so nothing is listening on it any more */ - listener = socket_tcp_listen(ip_loopback, 0); + listener = socket_tcp_listen(ip_loopback, 0, SOCKET_EXCLUSIVE); CHECK(listener != -1); bound_address(listener, listener_ip, &port); close(listener); @@ -247,8 +243,8 @@ static void case_bind_failure(void) { test_case("binding an address no interface carries fails"); before = next_descriptor(); CHECK(before != -1); - CHECK_INT(socket_tcp_listen(ip_unassigned, 0), -1); - CHECK_INT(socket_udp_bind(ip_unassigned, 0), -1); + CHECK_INT(socket_tcp_listen(ip_unassigned, 0, SOCKET_EXCLUSIVE), -1); + CHECK_INT(socket_udp_bind(ip_unassigned, 0, SOCKET_EXCLUSIVE), -1); test_case("a failed bind leaves no socket behind"); CHECK_INT(next_descriptor(), before); @@ -294,7 +290,7 @@ static void case_mcast_sender(void) { void test_socket(void) { case_socket_options(); #ifdef SO_REUSEPORT - case_reuseport_is_opt_in(); + case_sharing_is_opt_in(); #endif case_udp_roundtrip(); case_udp_v4mapped(); -- cgit v1.3