[vlc-commits] posix: add support for BSD SO_NOSIGPIPE socket option

Rémi Denis-Courmont git at videolan.org
Thu May 21 19:32:58 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 21 20:24:00 2015 +0300| [cb186021f68a7c349ca052bbf712f184ba8b5846] | committer: Rémi Denis-Courmont

posix: add support for BSD SO_NOSIGPIPE socket option

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cb186021f68a7c349ca052bbf712f184ba8b5846
---

 src/posix/filesystem.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index 6f97f02..79856e3 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;
 }



More information about the vlc-commits mailing list