From 531a9630a1b94a01d6627e373545f65c87698021 Mon Sep 17 00:00:00 2001 From: Mike Naquin Date: Wed, 17 Jul 2013 09:11:51 -0500 Subject: [PATCH] Ignore SIGPIPE on UNIX to keep sockets from crashing --- Net/src/SocketImpl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Net/src/SocketImpl.cpp b/Net/src/SocketImpl.cpp index 49b5dd90b..899751465 100644 --- a/Net/src/SocketImpl.cpp +++ b/Net/src/SocketImpl.cpp @@ -920,6 +920,15 @@ void SocketImpl::initSocket(int af, int type, int proto) _sockfd = ::socket(af, type, proto); if (_sockfd == POCO_INVALID_SOCKET) error(); + +#if defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__) + // SIGPIPE sends a signal that if unhandled (which is the default) + // will crash the process. This only happens on UNIX, and not Linux. + // + // In order to have POCO sockets behave the same across platforms, it is + // best to just ignore SIGPIPE all together. + setOption(SOL_SOCKET, SO_NOSIGPIPE, 1); +#endif }