diff options
author | Heikki Lindholm <holin@iki.fi> | 2009-10-18 05:10:41 +0000 |
---|---|---|
committer | Heikki Lindholm <holin@iki.fi> | 2009-10-18 05:10:41 +0000 |
commit | 85fe8817d96b112717df804be282f2bfd37aeaf7 (patch) | |
tree | cddd54ec011e224247e0391dd327b3ccb25380e6 /src/util/network.c | |
parent | e23e73bc2790e1185957157bc04675ba94ea9032 (diff) | |
download | gnunet-85fe8817d96b112717df804be282f2bfd37aeaf7.tar.gz gnunet-85fe8817d96b112717df804be282f2bfd37aeaf7.zip |
don't repeat setsockopt on every send
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/util/network.c b/src/util/network.c index 07364a36b..f3bf7ae83 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -102,7 +102,7 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | |||
102 | 102 | ||
103 | #ifndef MINGW | 103 | #ifndef MINGW |
104 | /** | 104 | /** |
105 | * Make a non-inheritable to child processes | 105 | * Make a socket non-inheritable to child processes |
106 | * | 106 | * |
107 | * @param h the socket to make non-inheritable | 107 | * @param h the socket to make non-inheritable |
108 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 108 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise |
@@ -124,6 +124,23 @@ socket_set_inheritable (const struct GNUNET_NETWORK_Handle | |||
124 | 124 | ||
125 | 125 | ||
126 | 126 | ||
127 | #ifdef OSX | ||
128 | /** | ||
129 | * The MSG_NOSIGNAL equivalent on Mac OS X | ||
130 | * | ||
131 | * @param h the socket to make non-delaying | ||
132 | */ | ||
133 | static void | ||
134 | socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle | ||
135 | *h) | ||
136 | { | ||
137 | int value = 1; | ||
138 | setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value)); | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | |||
143 | |||
127 | /** | 144 | /** |
128 | * Disable delays when sending data via the socket. | 145 | * Disable delays when sending data via the socket. |
129 | * (GNUnet makes sure that messages are as big as | 146 | * (GNUnet makes sure that messages are as big as |
@@ -187,6 +204,9 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
187 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 204 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
188 | "socket_set_inheritable"); | 205 | "socket_set_inheritable"); |
189 | #endif | 206 | #endif |
207 | #ifdef OSX | ||
208 | socket_set_nosigpipe (ret); | ||
209 | #endif | ||
190 | socket_set_nodelay (ret); | 210 | socket_set_nodelay (ret); |
191 | return ret; | 211 | return ret; |
192 | } | 212 | } |
@@ -351,13 +371,6 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, | |||
351 | { | 371 | { |
352 | int ret; | 372 | int ret; |
353 | int flags; | 373 | int flags; |
354 | #ifdef OSX | ||
355 | int no_sigpipe; | ||
356 | no_sigpipe = 1; | ||
357 | /* shouldn't matter if this fails as there's a SIGPIPE handler */ | ||
358 | ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE, | ||
359 | (void *) &no_sigpipe, sizeof (no_sigpipe)); | ||
360 | #endif | ||
361 | 374 | ||
362 | flags = 0; | 375 | flags = 0; |
363 | #ifdef MSG_DONTWAIT | 376 | #ifdef MSG_DONTWAIT |
@@ -395,13 +408,6 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | |||
395 | { | 408 | { |
396 | int ret; | 409 | int ret; |
397 | int flags; | 410 | int flags; |
398 | #ifdef OSX | ||
399 | int no_sigpipe; | ||
400 | no_sigpipe = 1; | ||
401 | /* shouldn't matter if this fails as there's a SIGPIPE handler */ | ||
402 | ret = setsockopt (desc->fd, SOL_SOCKET, SO_NOSIGPIPE, | ||
403 | (void *) &no_sigpipe, sizeof (no_sigpipe)); | ||
404 | #endif | ||
405 | 411 | ||
406 | flags = 0; | 412 | flags = 0; |
407 | #ifdef MSG_DONTWAIT | 413 | #ifdef MSG_DONTWAIT |
@@ -494,6 +500,9 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) | |||
494 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 500 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
495 | "socket_set_inheritable"); | 501 | "socket_set_inheritable"); |
496 | #endif | 502 | #endif |
503 | #ifdef OSX | ||
504 | socket_set_nosigpipe (ret); | ||
505 | #endif | ||
497 | if (type == SOCK_STREAM) | 506 | if (type == SOCK_STREAM) |
498 | socket_set_nodelay (ret); | 507 | socket_set_nodelay (ret); |
499 | 508 | ||