Skip to content

Commit

Permalink
Explicitly declare BSD's MSG_NOSIGNAL to suppress SIGPIPE
Browse files Browse the repository at this point in the history
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 deepfryed/beanstalk-client#32 (comment) for the hint
  • Loading branch information
HeroCC committed Dec 31, 2019
1 parent 3190eaf commit e388e4f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/uFrontNMEABridge/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/uFrontNMEABridge/Socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit e388e4f

Please sign in to comment.