From b6e7711e92c8b63675e4d2a2867610d390cb2ccc Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 14 Jul 2024 18:55:33 +0100 Subject: [PATCH] socket option SO_LINGER fix for macOS. SO_LINGER, on this platform, works differently than other unixes in that it does in term of clock ticks rather than seconds. Thus, the existence of the SO_LINGER_SEC option, we define it to every other platforms for simplicity sake. --- include/arch/unix/apr_arch_networkio.h | 7 +++++++ network_io/unix/sockopt.c | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/arch/unix/apr_arch_networkio.h b/include/arch/unix/apr_arch_networkio.h index 93c5f6d8e4..8ec5ec30fb 100644 --- a/include/arch/unix/apr_arch_networkio.h +++ b/include/arch/unix/apr_arch_networkio.h @@ -93,6 +93,13 @@ #define POLLNVAL 32 #endif +#ifdef SO_LINGER +/* SO_LINGER on macOS works in term of clock ticks */ +#ifndef SO_LINGER_SEC +#define SO_LINGER_SEC SO_LINGER +#endif +#endif + typedef struct sock_userdata_t sock_userdata_t; struct sock_userdata_t { sock_userdata_t *next; diff --git a/network_io/unix/sockopt.c b/network_io/unix/sockopt.c index 8579f5d7d9..a96cb8988b 100644 --- a/network_io/unix/sockopt.c +++ b/network_io/unix/sockopt.c @@ -193,12 +193,12 @@ apr_status_t apr_socket_opt_set(apr_socket_t *sock, } break; case APR_SO_LINGER: -#ifdef SO_LINGER +#ifdef SO_LINGER_SEC if (apr_is_option_set(sock, APR_SO_LINGER) != on) { struct linger li; li.l_onoff = on; li.l_linger = APR_MAX_SECS_TO_LINGER; - if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) { + if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER_SEC, (char *) &li, sizeof(struct linger)) == -1) { return errno; } apr_set_option(sock, APR_SO_LINGER, on);