]> git.sesse.net Git - vlc/commitdiff
Minor code factorization
authorRémi Denis-Courmont <rem@videolan.org>
Wed, 21 Feb 2007 17:42:19 +0000 (17:42 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Wed, 21 Feb 2007 17:42:19 +0000 (17:42 +0000)
include/vlc_network.h
src/network/io.c
src/network/tcp.c

index 0b9267586a3b473ab16f41b98ddb2760d9c58f5c..99a8df8e9d1182e0be70095a6309d1b72bcf3741 100644 (file)
@@ -69,6 +69,7 @@ extern "C" {
 
 /* Portable networking layer communication */
 int net_Socket (vlc_object_t *obj, int family, int socktype, int proto);
+int net_SetupSocket (int fd);
 
 #define net_Connect(a, b, c, d, e) __net_Connect(VLC_OBJECT(a), b, c, d, e)
 VLC_EXPORT( int, __net_Connect, (vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol) );
index 9624fa025781efd4c002cd31cfee58de29fb1b44..045bf21818492eb2f9a37c32c433d250febb79c0 100644 (file)
 extern int rootwrap_bind (int family, int socktype, int protocol,
                           const struct sockaddr *addr, size_t alen);
 
+int net_SetupSocket (int fd)
+{
+#if defined (WIN32) || defined (UNDER_CE)
+    ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
+#else
+    fcntl (fd, F_SETFD, FD_CLOEXEC);
+    fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+#endif
+
+    setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
+    return 0;
+}
+
+
 int net_Socket (vlc_object_t *p_this, int family, int socktype,
                 int protocol)
 {
@@ -79,14 +93,7 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype,
         return -1;
     }
 
-#if defined (WIN32) || defined (UNDER_CE)
-    ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
-#else
-    fcntl (fd, F_SETFD, FD_CLOEXEC);
-    fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
-#endif
-
-    setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
+    net_SetupSocket (fd);
 
 #ifdef IPV6_V6ONLY
     /*
index bdff1aced503da3b6053f1564d7773f00ebb584a..c5ed0034c425f4d942e99ad10b8672cc52c5d209 100644 (file)
@@ -321,13 +321,7 @@ int __net_Accept( vlc_object_t *p_this, int pi_fd[], mtime_t i_wait )
                          net_strerror (net_errno));
                 continue;
             }
-            setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int));
-#if defined (WIN32) || defined (UNDER_CE)
-            ioctlsocket (fd, FIONBIO, &(unsigned long){ 1 });
-#else
-            fcntl (fd, F_SETFD, FD_CLOEXEC);
-            fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
-#endif
+            net_SetupSocket (fd);
 
             /*
              * This round-robin trick ensures that the first sockets in