From e388e4f4270757a892269e60948aa29a90730141 Mon Sep 17 00:00:00 2001 From: Conlan Cesar Date: Tue, 31 Dec 2019 04:30:14 -0500 Subject: [PATCH] Explicitly declare BSD's MSG_NOSIGNAL to suppress SIGPIPE Tested on MacOS High Sierra. Recent BSD manpages for send(2) define MSG_NOSIGNAL to be 0x20000. The MacOS BSD variant doesn't declare MSG_NOSIGNAL, but does honor the value. So, we backport it. See https://www.freebsd.org/cgi/man.cgi?query=send&sektion=2&manpath=FreeBSD+12.1-stable Thanks https://github.com/deepfryed/beanstalk-client/issues/32#issuecomment-302902494 for the hint --- src/uFrontNMEABridge/Socket.cpp | 6 +----- src/uFrontNMEABridge/Socket.h | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/uFrontNMEABridge/Socket.cpp b/src/uFrontNMEABridge/Socket.cpp index 6514b0e..74cf46e 100644 --- a/src/uFrontNMEABridge/Socket.cpp +++ b/src/uFrontNMEABridge/Socket.cpp @@ -26,12 +26,8 @@ bool Socket::create() { return false; } - int on = 1; - #if defined(SO_NOSIGPIPE) - setsockopt(m_sock, SOL_SOCKET, SO_NOSIGPIPE, (const char *) &on, sizeof(on)); - #endif - // TIME_WAIT - argh + int on = 1; return setsockopt(m_sock, SOL_SOCKET, SO_REUSEADDR, (const char *) &on, sizeof(on)) != -1; } diff --git a/src/uFrontNMEABridge/Socket.h b/src/uFrontNMEABridge/Socket.h index b68a113..ce0968c 100644 --- a/src/uFrontNMEABridge/Socket.h +++ b/src/uFrontNMEABridge/Socket.h @@ -6,9 +6,9 @@ #ifndef Socket_HEADER #define Socket_HEADER -// MacOS doesn't have MSG_NOSIGNAL, default to 0 / nothing +// MacOS doesn't have MSG_NOSIGNAL, explicitly declare it #if defined(__APPLE__) && !defined(MSG_NOSIGNAL) -#define MSG_NOSIGNAL 0 +#define MSG_NOSIGNAL 0x2000 #endif