]> git.sesse.net Git - vlc/blobdiff - src/text/filesystem.c
net: fix socket blocking if accept4 not available
[vlc] / src / text / filesystem.c
index 1025238bc0ee06eb6842f8a694e6124d255eaea2..e230f058c10178b8a45f107e50bf716c1d71d4dd 100644 (file)
@@ -617,6 +617,8 @@ int vlc_dup (int oldfd)
     return newfd;
 }
 
+#include <vlc_network.h>
+
 /**
  * Creates a socket file descriptor. The new file descriptor has the
  * close-on-exec flag set.
@@ -634,7 +636,7 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
     type |= SOCK_CLOEXEC;
     if (nonblock)
         type |= SOCK_NONBLOCK;
-    fd = socket (pf, type | SOCK_NONBLOCK | SOCK_CLOEXEC, proto);
+    fd = socket (pf, type, proto);
     if (fd != -1 || errno != EINVAL)
         return fd;
 
@@ -691,7 +693,17 @@ int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
     {
         int fd = accept (lfd, addr, alen);
         if (fd != -1)
+        {
+#ifndef WIN32
+    fcntl (fd, F_SETFD, FD_CLOEXEC);
+    if (nonblock)
+        fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+#else
+    if (nonblock)
+        ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
+#endif
             return fd;
+        }
     }
     while (errno == EINTR);