]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pipe: handle missing MSG_MORE and MSG_NOSIGNAL
authorNoah Watkins <noahwatkins@gmail.com>
Mon, 22 Jul 2013 00:08:53 +0000 (17:08 -0700)
committerNoah Watkins <noahwatkins@gmail.com>
Sat, 4 Jan 2014 17:18:04 +0000 (09:18 -0800)
On OSX (and currently any platform missing the MSG_MORE
macro) the MSG_MORE optimization is disabled. The MSG_NOSIGNAL flag is
available on OSX but is called SO_NOSIGPIPE and must be set via
setsockopt.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
src/msg/Pipe.cc

index 66b64d0097a0c155260711cedd998863328d637c..4b9dcae8d17d2ade494deb2ad21cfd3e49d2c112 100644 (file)
@@ -48,7 +48,25 @@ ostream& Pipe::_pipe_prefix(std::ostream *_dout) {
                << ").";
 }
 
+/*
+ * This optimization may not be available on all platforms (e.g. OSX).
+ * Apparently a similar approach based on TCP_CORK can be used.
+ */
+#ifndef MSG_MORE
+# define MSG_MORE 0
+#endif
 
+/*
+ * On BSD SO_NOSIGPIPE can be set via setsockopt to block SIGPIPE.
+ */
+#ifndef MSG_NOSIGNAL
+# define MSG_NOSIGNAL 0
+# ifdef SO_NOSIGPIPE
+#  define CEPH_USE_SO_NOSIGPIPE
+# else
+#  error "Cannot block SIGPIPE!"
+# endif
+#endif
 
 /**************************************
  * Pipe
@@ -754,6 +772,16 @@ void Pipe::set_socket_options()
       ldout(msgr->cct,0) << "couldn't set SO_RCVBUF to " << size << ": " << cpp_strerror(r) << dendl;
     }
   }
+
+  // block ESIGPIPE
+#ifdef CEPH_USE_SO_NOSIGPIPE
+  int val = 1;
+  int r = ::setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void*)&val, sizeof(val));
+  if (r) {
+    r = -errno;
+    ldout(msgr->cct,0) << "couldn't set SO_NOSIGPIPE: " << cpp_strerror(r) << dendl;
+  }
+#endif
 }
 
 int Pipe::connect()