Skip to content

Commit 531a963

Browse files
author
Mike Naquin
committed
Ignore SIGPIPE on UNIX to keep sockets from crashing
1 parent ae26e45 commit 531a963

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎Net/src/SocketImpl.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,15 @@ void SocketImpl::initSocket(int af, int type, int proto)
920920
_sockfd = ::socket(af, type, proto);
921921
if (_sockfd == POCO_INVALID_SOCKET)
922922
error();
923+
924+
#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__)
925+
// SIGPIPE sends a signal that if unhandled (which is the default)
926+
// will crash the process. This only happens on UNIX, and not Linux.
927+
//
928+
// In order to have POCO sockets behave the same across platforms, it is
929+
// best to just ignore SIGPIPE all together.
930+
setOption(SOL_SOCKET, SO_NOSIGPIPE, 1);
931+
#endif
923932
}
924933

925934

0 commit comments

Comments
 (0)