summaryrefslogtreecommitdiffstats
path: root/src/TcpSocket.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-12-08 08:36:35 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-12-08 08:36:35 +0100
commitfd026d844d62d575d555b25dc48a1d7ce9a7db42 (patch)
tree45223400a0f93b94180559e4a7e3897f915dc1ed /src/TcpSocket.cpp
parentd573723196f4f0c97e64d5a3a7adbabd3d51a429 (diff)
downloaddabmux-fd026d844d62d575d555b25dc48a1d7ce9a7db42.tar.gz
dabmux-fd026d844d62d575d555b25dc48a1d7ce9a7db42.tar.bz2
dabmux-fd026d844d62d575d555b25dc48a1d7ce9a7db42.zip
Portability: check for MSG_NOSIGNAL and SO_NOSIGPIPE
Diffstat (limited to 'src/TcpSocket.cpp')
-rw-r--r--src/TcpSocket.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp
index 40c1c1a..69b6df5 100644
--- a/src/TcpSocket.cpp
+++ b/src/TcpSocket.cpp
@@ -55,6 +55,14 @@ TcpSocket::TcpSocket(int port, const string& name) :
throw std::runtime_error("Can't reuse address");
}
+#if defined(HAVE_SO_NOSIGPIPE)
+ int val = 1;
+ if (setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val))
+ == SOCKET_ERROR) {
+ throw std::runtime_error("Can't set SO_NOSIGPIPE");
+ }
+#endif
+
m_own_address.setAddress(name);
m_own_address.setPort(port);
@@ -152,8 +160,15 @@ ssize_t TcpSocket::send(const void* data, size_t size, int timeout_ms)
}
}
- /* Without MSG_NOSIGNAL the process would receive a SIGPIPE and die */
- ssize_t ret = ::send(m_sock, (const char*)data, size, MSG_NOSIGNAL);
+ /* On Linux, the MSG_NOSIGNAL flag ensures that the process would not
+ * receive a SIGPIPE and die.
+ * Other systems have SO_NOSIGPIPE set on the socket for the same effect. */
+#if defined(HAVE_MSG_NOSIGNAL)
+ const int flags = MSG_NOSIGNAL;
+#else
+ const int flags = 0;
+#endif
+ ssize_t ret = ::send(m_sock, (const char*)data, size, flags);
if (ret == SOCKET_ERROR) {
stringstream ss;