THRIFT-2019: Writing on a disconnected socket on Mac causes SIG PIPE
authorBen Craig <bencraig@apache.org>
Wed, 9 Oct 2013 20:27:38 +0000 (15:27 -0500)
committerBen Craig <bencraig@apache.org>
Wed, 9 Oct 2013 20:27:38 +0000 (15:27 -0500)
Client: cpp
Patch: Ben Craig

lib/cpp/src/thrift/transport/TSocket.cpp

index 381daa2..1896457 100755 (executable)
@@ -144,6 +144,12 @@ TSocket::TSocket(THRIFT_SOCKET socket) :
   recvTimeval_.tv_sec = (int)(recvTimeout_/1000);
   recvTimeval_.tv_usec = (int)((recvTimeout_%1000)*1000);
   cachedPeerAddr_.ipv4.sin_family = AF_UNSPEC;
+#ifdef SO_NOSIGPIPE
+  {
+    int one = 1;
+    setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
+  }
+#endif
 }
 
 TSocket::~TSocket() {
@@ -217,6 +223,13 @@ void TSocket::openConnection(struct addrinfo *res) {
   // No delay
   setNoDelay(noDelay_);
 
+#ifdef SO_NOSIGPIPE
+  {
+    int one = 1;
+    setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one));
+  }
+#endif
+
   // Uses a low min RTO if asked to.
 #ifdef TCP_LOW_MIN_RTO
   if (getUseLowMinRto()) {