From 6163bc392bd353c2157d3e5a29bf914ada541100 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sat, 20 Jul 2024 08:23:59 +0200 Subject: [PATCH] Fix socket send call on platforms without MSG_NOSIGNAL To fix build issue encountered on MacOS Catalina but may apply to other platforms. --- src/socket.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/socket.c b/src/socket.c index a4de8aa..e51f937 100644 --- a/src/socket.c +++ b/src/socket.c @@ -226,7 +226,11 @@ void socket_configure(void) exit(EXIT_FAILURE); } +#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) + if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR | SO_NOSIGPIPE, &optval, sizeof(optval))) +#else if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))) +#endif { tio_error_printf("Failed to set socket options (%s)", strerror(errno)); exit(EXIT_FAILURE); @@ -270,7 +274,12 @@ void socket_write(char input_char) { if (clientfds[i] != -1) { + +#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) + if (send(clientfds[i], &input_char, 1, 0) <= 0) +#else if (send(clientfds[i], &input_char, 1, MSG_NOSIGNAL) <= 0) +#endif { tio_error_printf_silent("Failed to write to socket (%s)", strerror(errno)); close(clientfds[i]);