Set SO_NOSIGPIPE on Darwin to stop from breaking into the debugger every time a connection closes

This commit is contained in:
Cameron Gutman 2014-10-21 14:17:52 -04:00
parent affcb84d36
commit e56f13b123
2 changed files with 19 additions and 0 deletions

View File

@ -21,6 +21,9 @@
# endif
#else
# define LC_POSIX
# if defined(__APPLE__)
# define LC_DARWIN
# endif
#endif
#include <stdio.h>

View File

@ -21,6 +21,13 @@ SOCKET bindUdpSocket(void) {
return INVALID_SOCKET;
}
#ifdef LC_DARWIN
// Disable SIGPIPE on iOS
val = 1;
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char* )&val, sizeof(val));
#endif
// Set the receive buffer to 64KB by default
val = 65536;
setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*) &val, sizeof(val));
@ -31,12 +38,21 @@ SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port) {
SOCKET s;
struct sockaddr_in addr;
int err;
#ifdef LC_DARWIN
int val;
#endif
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET) {
return INVALID_SOCKET;
}
#ifdef LC_DARWIN
// Disable SIGPIPE on iOS
val = 1;
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (char* )&val, sizeof(val));
#endif
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);