Use instead SO_LINGER with timeout of 0 seconds

This commit is contained in:
JP Meijers 2026-02-24 16:05:10 +02:00
parent 0e93d6e453
commit 4d7c07a2f3
No known key found for this signature in database
GPG Key ID: 57E7B2C7D93F3D34
1 changed files with 5 additions and 3 deletions

View File

@ -283,10 +283,12 @@ bool server_http_context::start() {
} else {
LOG_INF("%s: binding port with default address family\n", __func__);
// Enable address reuse to allow immediate restart of server
// Set linger time to 0 to force close the socket immediately when the server stops
srv->set_socket_options([](socket_t sock) {
const char flag = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
linger sl{};
sl.l_onoff = 1;
sl.l_linger = 0;
setsockopt(sock, SOL_SOCKET, SO_LINGER, reinterpret_cast<const char *>(&sl), sizeof(sl));
});
// bind HTTP listen port