network: prevent SIGPIPE on OSX

OSX does not know MSG_NOSIGNAL. BSD (which OSX is based on) has got
the socket option SO_NOSIGPIPE (even if modern BSDs also support
MSG_NOSIGNAL).

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
wm4 2015-05-28 18:23:27 +02:00 committed by Martin Storsjö
parent 0181ae9af2
commit 881b80b329
1 changed files with 4 additions and 0 deletions

View File

@ -153,6 +153,10 @@ int ff_socket(int af, int type, int proto)
fcntl(fd, F_SETFD, FD_CLOEXEC);
#endif
}
#ifdef SO_NOSIGPIPE
if (fd != -1)
setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int));
#endif
return fd;
}