[vlc-commits] commit: vlc_accept: accept() with close-on-exec ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Wed Mar 31 18:29:51 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Mar 31 19:23:47 2010 +0300| [a2f2d51d0329cad437db4617c3f2b6584265a8a8] | committer: Rémi Denis-Courmont 

vlc_accept: accept() with close-on-exec

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

 include/vlc_fs.h      |    5 ++++-
 src/libvlccore.sym    |    1 +
 src/text/filesystem.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/include/vlc_fs.h b/include/vlc_fs.h
index 9ff8200..5bdd10c 100644
--- a/include/vlc_fs.h
+++ b/include/vlc_fs.h
@@ -54,6 +54,9 @@ VLC_EXPORT( int, vlc_lstat, ( const char *filename, struct stat *buf ) );
 VLC_EXPORT( int, vlc_mkstemp, ( char * ) );
 
 VLC_EXPORT( int, vlc_dup, ( int ) );
-int vlc_socket (int, int, int, bool nonblock);
+int vlc_socket (int, int, int, bool nonblock) LIBVLC_USED;
+
+struct sockaddr;
+VLC_EXPORT( int, vlc_accept, ( int, struct sockaddr *, socklen_t *, bool ) LIBVLC_USED );
 
 #endif
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 3ab5bf4..e618f92 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -445,6 +445,7 @@ vlc_stat
 vlc_unlink
 vlc_rename
 vlc_dup
+vlc_accept
 utf8_vfprintf
 var_AddCallback
 var_Change
diff --git a/src/text/filesystem.c b/src/text/filesystem.c
index a0d1050..1025238 100644
--- a/src/text/filesystem.c
+++ b/src/text/filesystem.c
@@ -655,3 +655,45 @@ int vlc_socket (int pf, int type, int proto, bool nonblock)
 #endif
     return fd;
 }
+
+/**
+ * Accepts an inbound connection request on a listening socket.
+ * The new file descriptor has the close-on-exec flag set.
+ * @param lfd listening socket file descriptor
+ * @param addr pointer to the peer address or NULL [OUT]
+ * @param alen pointer to the length of the peer address or NULL [OUT]
+ * @param nonblock whether to put the new socket in non-blocking mode
+ * @return a new file descriptor, or -1 on error.
+ */
+int vlc_accept (int lfd, struct sockaddr *addr, socklen_t *alen, bool nonblock)
+{
+#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);
+
+    if (errno != ENOSYS)
+        return -1;
+#endif
+#ifdef WIN32
+    errno = 0;
+#endif
+
+    do
+    {
+        int fd = accept (lfd, addr, alen);
+        if (fd != -1)
+            return fd;
+    }
+    while (errno == EINTR);
+
+    return -1;
+}



More information about the vlc-commits mailing list