/* 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) );
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)
{
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
/*
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