]> git.sesse.net Git - vlc/commitdiff
net: fix socket blocking if accept4 not available
authorErwan Tulou <erwan10@videolan.org>
Sat, 3 Apr 2010 15:30:17 +0000 (17:30 +0200)
committerErwan Tulou <erwan10@videolan.org>
Sat, 3 Apr 2010 16:54:14 +0000 (18:54 +0200)
same options needed for vlc_accept as those for vlc_socket

src/text/filesystem.c

index 40a158a75cb51a462a814752720732cb39df9582..e230f058c10178b8a45f107e50bf716c1d71d4dd 100644 (file)
@@ -636,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;
 
@@ -693,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);