[vlc-commits] posix: revector vlc_accept()

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:23:24 2015 +0300| [bc43f3ac8c0e71f779e6f816f6b7e536e299308b] | committer: Rémi Denis-Courmont

posix: revector vlc_accept()

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

 src/posix/filesystem.c |   32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index 45df501..6f97f02 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -318,35 +318,29 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
  */
 int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
 {
+    int fd;
 #ifdef HAVE_ACCEPT4
     int flags = SOCK_CLOEXEC;
     if (nonblock)
         flags |= SOCK_NONBLOCK;
 
     do
-    {
-        int fd = accept4 (lfd, addr, alen, flags);
-        if (fd != -1)
-            return fd;
-    }
-    while (errno == EINTR);
+        fd = accept4 (lfd, addr, alen, flags);
+    while (fd == -1 && errno == EINTR);
 
-    if (errno != ENOSYS)
-        return -1;
+    if (fd != -1 || errno != ENOSYS)
+        return fd;
 #endif
 
     do
+        fd = accept (lfd, addr, alen);
+    while (fd == -1 && errno == EINTR);
+
+    if (fd != -1)
     {
-        int fd = accept (lfd, addr, alen);
-        if (fd != -1)
-        {
-            fcntl (fd, F_SETFD, FD_CLOEXEC);
-            if (nonblock)
-                fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
-            return fd;
-        }
+        fcntl (fd, F_SETFD, FD_CLOEXEC);
+        if (nonblock)
+            fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
     }
-    while (errno == EINTR);
-
-    return -1;
+    return fd;
 }



More information about the vlc-commits mailing list