From: RĂ©mi Denis-Courmont Date: Wed, 21 Feb 2007 17:42:19 +0000 (+0000) Subject: Minor code factorization X-Git-Tag: 0.9.0-test0~8497 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f9279bb46db3777459df7c0fb67b01ead1ffa0ee;p=vlc Minor code factorization --- diff --git a/include/vlc_network.h b/include/vlc_network.h index 0b9267586a..99a8df8e9d 100644 --- a/include/vlc_network.h +++ b/include/vlc_network.h @@ -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) ); diff --git a/src/network/io.c b/src/network/io.c index 9624fa0257..045bf21818 100644 --- a/src/network/io.c +++ b/src/network/io.c @@ -67,6 +67,20 @@ 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 /* diff --git a/src/network/tcp.c b/src/network/tcp.c index bdff1aced5..c5ed0034c4 100644 --- a/src/network/tcp.c +++ b/src/network/tcp.c @@ -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