Commit f9279bb4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Minor code factorization

parent 412ce0dd
...@@ -69,6 +69,7 @@ extern "C" { ...@@ -69,6 +69,7 @@ extern "C" {
/* Portable networking layer communication */ /* Portable networking layer communication */
int net_Socket (vlc_object_t *obj, int family, int socktype, int proto); 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) #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) ); VLC_EXPORT( int, __net_Connect, (vlc_object_t *p_this, const char *psz_host, int i_port, int socktype, int protocol) );
......
...@@ -67,6 +67,20 @@ ...@@ -67,6 +67,20 @@
extern int rootwrap_bind (int family, int socktype, int protocol, extern int rootwrap_bind (int family, int socktype, int protocol,
const struct sockaddr *addr, size_t alen); 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 net_Socket (vlc_object_t *p_this, int family, int socktype,
int protocol) int protocol)
{ {
...@@ -79,14 +93,7 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype, ...@@ -79,14 +93,7 @@ int net_Socket (vlc_object_t *p_this, int family, int socktype,
return -1; return -1;
} }
#if defined (WIN32) || defined (UNDER_CE) net_SetupSocket (fd);
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));
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
/* /*
......
...@@ -321,13 +321,7 @@ int __net_Accept( vlc_object_t *p_this, int pi_fd[], mtime_t i_wait ) ...@@ -321,13 +321,7 @@ int __net_Accept( vlc_object_t *p_this, int pi_fd[], mtime_t i_wait )
net_strerror (net_errno)); net_strerror (net_errno));
continue; continue;
} }
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof (int)); net_SetupSocket (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
/* /*
* This round-robin trick ensures that the first sockets in * This round-robin trick ensures that the first sockets in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment