don't repeat setsockopt on every send
authorHeikki Lindholm <holin@iki.fi>
Sun, 18 Oct 2009 05:10:41 +0000 (05:10 +0000)
committerHeikki Lindholm <holin@iki.fi>
Sun, 18 Oct 2009 05:10:41 +0000 (05:10 +0000)
src/util/network.c

index 07364a36b8b9e99b9fa090f01daf43a592aef951..f3bf7ae837e0b52195d5460c8c0d2d3d3b8a7d9b 100644 (file)
@@ -102,7 +102,7 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
 \r
 #ifndef MINGW\r
 /**\r
- * Make a non-inheritable to child processes\r
+ * Make a socket non-inheritable to child processes\r
  *\r
  * @param h the socket to make non-inheritable\r
  * @return GNUNET_OK on success, GNUNET_SYSERR otherwise\r
@@ -124,6 +124,23 @@ socket_set_inheritable (const struct GNUNET_NETWORK_Handle
 \r
 \r
 \r
+#ifdef OSX\r
+/**\r
+ * The MSG_NOSIGNAL equivalent on Mac OS X\r
+ *\r
+ * @param h the socket to make non-delaying\r
+ */\r
+static void\r
+socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle\r
+                   *h)\r
+{\r
+  int value = 1;\r
+  setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value));\r
+}\r
+#endif\r
+\r
+\r
+\r
 /**\r
  * Disable delays when sending data via the socket.\r
  * (GNUnet makes sure that messages are as big as\r
@@ -186,6 +203,9 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
   if (GNUNET_OK != socket_set_inheritable (ret))\r
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,\r
                         "socket_set_inheritable");\r
+#endif\r
+#ifdef OSX\r
+  socket_set_nosigpipe (ret);  \r
 #endif\r
   socket_set_nodelay (ret);\r
   return ret;\r
@@ -351,13 +371,6 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
 {\r
   int ret;\r
   int flags;\r
-#ifdef OSX\r
-  int no_sigpipe;\r
-  no_sigpipe = 1;\r
-  /* shouldn't matter if this fails as there's a SIGPIPE handler */\r
-  ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE,\r
-                    (void *) &no_sigpipe, sizeof (no_sigpipe));\r
-#endif\r
 \r
   flags = 0;\r
 #ifdef MSG_DONTWAIT\r
@@ -395,13 +408,6 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
 {\r
   int ret;\r
   int flags;\r
-#ifdef OSX\r
-  int no_sigpipe;\r
-  no_sigpipe = 1;\r
-  /* shouldn't matter if this fails as there's a SIGPIPE handler */\r
-  ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE,\r
-                    (void *) &no_sigpipe, sizeof (no_sigpipe));\r
-#endif\r
 \r
   flags = 0;\r
 #ifdef MSG_DONTWAIT\r
@@ -493,6 +499,9 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
   if (GNUNET_OK != socket_set_inheritable (ret))\r
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,\r
                         "socket_set_inheritable");\r
+#endif\r
+#ifdef OSX\r
+  socket_set_nosigpipe (ret);  \r
 #endif\r
   if (type == SOCK_STREAM)\r
     socket_set_nodelay (ret);\r