diff options
-rw-r--r-- | toxcore/TCP_client.c | 7 | ||||
-rw-r--r-- | toxcore/TCP_server.c | 5 | ||||
-rw-r--r-- | toxcore/TCP_server.h | 2 | ||||
-rw-r--r-- | toxcore/network.c | 15 | ||||
-rw-r--r-- | toxcore/network.h | 7 |
5 files changed, 34 insertions, 2 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 9c6003ae..18f63c5f 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -253,6 +253,11 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, uint8_t *public_key, | |||
253 | return NULL; | 253 | return NULL; |
254 | } | 254 | } |
255 | 255 | ||
256 | if (!set_socket_nosigpipe(sock)) { | ||
257 | kill_sock(sock); | ||
258 | return 0; | ||
259 | } | ||
260 | |||
256 | if (!(set_socket_nonblock(sock) && connect_sock_to(sock, ip_port))) { | 261 | if (!(set_socket_nonblock(sock) && connect_sock_to(sock, ip_port))) { |
257 | kill_sock(sock); | 262 | kill_sock(sock); |
258 | return NULL; | 263 | return NULL; |
@@ -433,4 +438,4 @@ void kill_TCP_connection(TCP_Client_Connection *TCP_connection) | |||
433 | kill_sock(TCP_connection->sock); | 438 | kill_sock(TCP_connection->sock); |
434 | memset(TCP_connection, 0, sizeof(TCP_Client_Connection)); | 439 | memset(TCP_connection, 0, sizeof(TCP_Client_Connection)); |
435 | free(TCP_connection); | 440 | free(TCP_connection); |
436 | } \ No newline at end of file | 441 | } |
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 847f04e7..410111f4 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -702,6 +702,11 @@ static int accept_connection(TCP_Server *TCP_server, sock_t sock) | |||
702 | return 0; | 702 | return 0; |
703 | } | 703 | } |
704 | 704 | ||
705 | if (!set_socket_nosigpipe(sock)) { | ||
706 | kill_sock(sock); | ||
707 | return 0; | ||
708 | } | ||
709 | |||
705 | TCP_Secure_Connection *conn = | 710 | TCP_Secure_Connection *conn = |
706 | &TCP_server->incomming_connection_queue[TCP_server->incomming_connection_queue_index % MAX_INCOMMING_CONNECTIONS]; | 711 | &TCP_server->incomming_connection_queue[TCP_server->incomming_connection_queue_index % MAX_INCOMMING_CONNECTIONS]; |
707 | 712 | ||
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index 57313038..498b1147 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #include "net_crypto.h" | 26 | #include "net_crypto.h" |
27 | #include "onion.h" | 27 | #include "onion.h" |
28 | 28 | ||
29 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 29 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__MACH__) |
30 | #define MSG_NOSIGNAL 0 | 30 | #define MSG_NOSIGNAL 0 |
31 | #endif | 31 | #endif |
32 | 32 | ||
diff --git a/toxcore/network.c b/toxcore/network.c index 47afab8e..7813ab03 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -150,6 +150,21 @@ int set_socket_nonblock(sock_t sock) | |||
150 | #endif | 150 | #endif |
151 | } | 151 | } |
152 | 152 | ||
153 | /* Set socket to not emit SIGPIPE | ||
154 | * | ||
155 | * return 1 on success | ||
156 | * return 0 on failure | ||
157 | */ | ||
158 | int set_socket_nosigpipe(sock_t sock) | ||
159 | { | ||
160 | #if defined(__MACH__) | ||
161 | int set = 1; | ||
162 | return (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int)) == 0); | ||
163 | #else | ||
164 | return 1; | ||
165 | #endif | ||
166 | } | ||
167 | |||
153 | /* Set socket to dual (IPv4 + IPv6 socket) | 168 | /* Set socket to dual (IPv4 + IPv6 socket) |
154 | * | 169 | * |
155 | * return 1 on success | 170 | * return 1 on success |
diff --git a/toxcore/network.h b/toxcore/network.h index 42ade800..ef040bf3 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -332,6 +332,13 @@ void kill_sock(sock_t sock); | |||
332 | */ | 332 | */ |
333 | int set_socket_nonblock(sock_t sock); | 333 | int set_socket_nonblock(sock_t sock); |
334 | 334 | ||
335 | /* Set socket to not emit SIGPIPE | ||
336 | * | ||
337 | * return 1 on success | ||
338 | * return 0 on failure | ||
339 | */ | ||
340 | int set_socket_nosigpipe(sock_t sock); | ||
341 | |||
335 | /* Set socket to dual (IPv4 + IPv6 socket) | 342 | /* Set socket to dual (IPv4 + IPv6 socket) |
336 | * | 343 | * |
337 | * return 1 on success | 344 | * return 1 on success |