From cb186021f68a7c349ca052bbf712f184ba8b5846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 21 May 2015 20:24:00 +0300 Subject: [PATCH] posix: add support for BSD SO_NOSIGPIPE socket option --- src/posix/filesystem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c index 6f97f0224d..79856e3234 100644 --- a/src/posix/filesystem.c +++ b/src/posix/filesystem.c @@ -304,6 +304,9 @@ int vlc_socket (int pf, int type, int proto, bool nonblock) fcntl (fd, F_SETFD, FD_CLOEXEC); if (nonblock) fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK); +#ifdef SO_NOSIGPIPE + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){ 1 }, sizeof (int)); +#endif return fd; } @@ -328,6 +331,10 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock) fd = accept4 (lfd, addr, alen, flags); while (fd == -1 && errno == EINTR); +# ifdef SO_NOSIGPIPE + if (fd != -1) + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){ 1 }, sizeof (int)); +# endif if (fd != -1 || errno != ENOSYS) return fd; #endif @@ -341,6 +348,9 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock) fcntl (fd, F_SETFD, FD_CLOEXEC); if (nonblock) fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK); +#ifdef SO_NOSIGPIPE + setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){ 1 }, sizeof (int)); +#endif } return fd; }