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

Hmm, damn stupid fd_set implementation by Winsock does of course not

work like any other one: it's actually thirty two times as big than the
POSIX ones for any given FD_SETSIZE, plus FD_SET and FD_ISSET are O(n)
instead of O(1). But at least, the mingw implementations of FD_SET has
built-in overflow checks.

Also, Winsock insists on returning big socket numbers, so we can't drop
those above FD_SETSIZE or we have no TCP/IP support at all, anyway.

parent 561a7d3d
...@@ -69,14 +69,6 @@ int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype, ...@@ -69,14 +69,6 @@ int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
return -1; return -1;
} }
if( fd >= FD_SETSIZE )
{
msg_Err( p_this, "cannot create socket (too many already in use)" );
net_Close( fd );
return -1;
}
/* Set to non-blocking */
#if defined( WIN32 ) || defined( UNDER_CE ) #if defined( WIN32 ) || defined( UNDER_CE )
{ {
unsigned long i_dummy = 1; unsigned long i_dummy = 1;
...@@ -84,12 +76,17 @@ int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype, ...@@ -84,12 +76,17 @@ int net_Socket( vlc_object_t *p_this, int i_family, int i_socktype,
msg_Err( p_this, "cannot set socket to non-blocking mode" ); msg_Err( p_this, "cannot set socket to non-blocking mode" );
} }
#else #else
fcntl( fd, F_SETFD, FD_CLOEXEC ); if( fd >= FD_SETSIZE )
{
/* We don't want to overflow select() fd_set */
msg_Err( p_this, "cannot create socket (too many already in use)" );
net_Close( fd );
return -1;
}
if( ( ( i_val = fcntl( fd, F_GETFL, 0 ) ) < 0 ) || fcntl( fd, F_SETFD, FD_CLOEXEC );
( fcntl( fd, F_SETFL, i_val | O_NONBLOCK ) < 0 ) ) i_val = fcntl( fd, F_GETFL, 0 );
msg_Err( p_this, "cannot set socket to non-blocking mode (%s)", fcntl( fd, F_SETFL, ((i_val != -1) ? i_val : 0) | O_NONBLOCK );
strerror( errno ) );
#endif #endif
i_val = 1; i_val = 1;
......
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