Commit de8390cd authored by Gildas Bazin's avatar Gildas Bazin

* modules/misc/network/ipv4.c: got rid of the #ifdef HAVE_ERRNO_H + WinCE compilation fixes.

parent af338f59
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <errno.h>
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
...@@ -36,9 +37,6 @@ ...@@ -36,9 +37,6 @@
#ifdef HAVE_SYS_STAT_H #ifdef HAVE_SYS_STAT_H
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
# include <fcntl.h> # include <fcntl.h>
#endif #endif
...@@ -49,6 +47,7 @@ ...@@ -49,6 +47,7 @@
#if defined( UNDER_CE ) #if defined( UNDER_CE )
# include <winsock.h> # include <winsock.h>
# define close(fd) CloseHandle((HANDLE)fd)
#elif defined( WIN32 ) #elif defined( WIN32 )
# include <winsock2.h> # include <winsock2.h>
# include <ws2tcpip.h> # include <ws2tcpip.h>
...@@ -182,10 +181,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -182,10 +181,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
* protocol */ * protocol */
if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 ) if( (i_handle = socket( AF_INET, SOCK_DGRAM, 0 )) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot create socket (%i)", WSAGetLastError() );
#else #else
msg_Warn( p_this, "cannot create socket" ); msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
#endif #endif
return( -1 ); return( -1 );
} }
...@@ -195,27 +194,38 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -195,27 +194,38 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR, if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEADDR,
(void *) &i_opt, sizeof( i_opt ) ) == -1 ) (void *) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %i)",
WSAGetLastError() );
#else
msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %s)", msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR: %s)",
strerror(errno)); strerror(errno));
#else
msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR)" );
#endif #endif
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
} }
#ifdef SO_REUSEPORT
i_opt = 1;
if( setsockopt( i_handle, SOL_SOCKET, SO_REUSEPORT,
(void *) &i_opt, sizeof( i_opt ) ) == -1 )
{
msg_Warn( p_this, "cannot configure socket (SO_REUSEPORT)" );
}
#endif
/* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid /* Increase the receive buffer size to 1/2MB (8Mb/s during 1/2s) to avoid
* packet loss caused by scheduling problems */ * packet loss caused by scheduling problems */
i_opt = 0x80000; i_opt = 0x80000;
#if !defined( SYS_BEOS ) #if !defined( SYS_BEOS )
if( setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, (void *) &i_opt, sizeof( i_opt ) ) == -1 ) if( setsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, (void *) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Dbg( p_this, "cannot configure socket (SO_RCVBUF: %i)",
WSAGetLastError() );
#else
msg_Dbg( p_this, "cannot configure socket (SO_RCVBUF: %s)", msg_Dbg( p_this, "cannot configure socket (SO_RCVBUF: %s)",
strerror(errno)); strerror(errno));
#else
msg_Warn( p_this, "cannot configure socket (SO_RCVBUF)" );
#endif #endif
} }
#endif #endif
...@@ -228,11 +238,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -228,11 +238,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
i_opt_size = sizeof( i_opt ); i_opt_size = sizeof( i_opt );
if( getsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, (void*) &i_opt, &i_opt_size ) == -1 ) if( getsockopt( i_handle, SOL_SOCKET, SO_RCVBUF, (void*) &i_opt, &i_opt_size ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %i)",
WSAGetLastError() );
#else
msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %s)", msg_Warn( p_this, "cannot query socket (SO_RCVBUF: %s)",
strerror(errno) ); strerror(errno) );
#else
msg_Warn( p_this, "cannot query socket (SO_RCVBUF)" );
#endif #endif
} }
else if( i_opt < 0x80000 ) else if( i_opt < 0x80000 )
...@@ -262,10 +273,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -262,10 +273,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
/* Bind it */ /* Bind it */
if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 ) if( bind( i_handle, (struct sockaddr *)&sock, sizeof( sock ) ) < 0 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot bind socket (%i)", WSAGetLastError() );
#else #else
msg_Warn( p_this, "cannot bind socket" ); msg_Warn( p_this, "cannot bind socket (%s)", strerror(errno) );
#endif #endif
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
...@@ -291,11 +302,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -291,11 +302,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
i_opt = 1; i_opt = 1;
if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST, (void*) &i_opt, sizeof( i_opt ) ) == -1 ) if( setsockopt( i_handle, SOL_SOCKET, SO_BROADCAST, (void*) &i_opt, sizeof( i_opt ) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot configure socket (SO_BROADCAST: %i)",
WSAGetLastError() );
#else
msg_Warn( p_this, "cannot configure socket (SO_BROADCAST: %s)", msg_Warn( p_this, "cannot configure socket (SO_BROADCAST: %s)",
strerror(errno) ); strerror(errno) );
#else
msg_Warn( p_this, "cannot configure socket (SO_BROADCAST)" );
#endif #endif
} }
} }
...@@ -335,14 +347,14 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -335,14 +347,14 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
(char*)&imr, (char*)&imr,
sizeof(struct ip_mreq_source) ) == -1 ) sizeof(struct ip_mreq_source) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Err( p_this, "failed to join IP multicast group (%i)",
WSAGetLastError() );
#else
msg_Err( p_this, "failed to join IP multicast group (%s)", msg_Err( p_this, "failed to join IP multicast group (%s)",
strerror(errno) ); strerror(errno) );
msg_Err( p_this, "are you sure your OS supports IGMPv3?" );
#else
msg_Err( p_this, "failed to join IP multicast group" );
msg_Err( p_this, "are you sure your OS supports IGMPv3?" );
#endif #endif
msg_Err( p_this, "are you sure your OS supports IGMPv3?" );
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
} }
...@@ -369,11 +381,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -369,11 +381,12 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP, if( setsockopt( i_handle, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char*)&imr, sizeof(struct ip_mreq) ) == -1 ) (char*)&imr, sizeof(struct ip_mreq) ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Err( p_this, "failed to join IP multicast group (%i)",
WSAGetLastError() );
#else
msg_Err( p_this, "failed to join IP multicast group (%s)", msg_Err( p_this, "failed to join IP multicast group (%s)",
strerror(errno) ); strerror(errno) );
#else
msg_Err( p_this, "failed to join IP multicast group" );
#endif #endif
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
...@@ -396,10 +409,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -396,10 +409,10 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( connect( i_handle, (struct sockaddr *) &sock, if( connect( i_handle, (struct sockaddr *) &sock,
sizeof( sock ) ) == (-1) ) sizeof( sock ) ) == (-1) )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot connect socket (%i)", WSAGetLastError());
#else #else
msg_Warn( p_this, "cannot connect socket" ); msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
#endif #endif
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
...@@ -432,19 +445,13 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -432,19 +445,13 @@ static int OpenUDP( vlc_object_t * p_this, network_socket_t * p_socket )
if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_TTL, if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_TTL,
&ttl, sizeof( ttl ) ) < 0 ) &ttl, sizeof( ttl ) ) < 0 )
{ {
#ifdef HAVE_ERRNO_H
msg_Dbg( p_this, "failed to set ttl (%s). Let's try it " msg_Dbg( p_this, "failed to set ttl (%s). Let's try it "
"the integer way.", strerror(errno) ); "the integer way.", strerror(errno) );
#endif
if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_TTL, if( setsockopt( i_handle, IPPROTO_IP, IP_MULTICAST_TTL,
&i_ttl, sizeof( i_ttl ) ) <0 ) &i_ttl, sizeof( i_ttl ) ) <0 )
{ {
#ifdef HAVE_ERRNO_H
msg_Err( p_this, "failed to set ttl (%s)", msg_Err( p_this, "failed to set ttl (%s)",
strerror(errno) ); strerror(errno) );
#else
msg_Err( p_this, "failed to set ttl" );
#endif
close( i_handle ); close( i_handle );
return( -1 ); return( -1 );
} }
...@@ -477,10 +484,10 @@ static int SocketTCP( vlc_object_t * p_this ) ...@@ -477,10 +484,10 @@ static int SocketTCP( vlc_object_t * p_this )
* protocol */ * protocol */
if( (i_handle = socket( PF_INET, SOCK_STREAM, 0 )) == -1 ) if( (i_handle = socket( PF_INET, SOCK_STREAM, 0 )) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot create socket (%i)", WSAGetLastError() );
#else #else
msg_Warn( p_this, "cannot create socket" ); msg_Warn( p_this, "cannot create socket (%s)", strerror(errno) );
#endif #endif
return -1; return -1;
} }
...@@ -494,7 +501,7 @@ static int SocketTCP( vlc_object_t * p_this ) ...@@ -494,7 +501,7 @@ static int SocketTCP( vlc_object_t * p_this )
msg_Err( p_this, "cannot set socket to non-blocking mode" ); msg_Err( p_this, "cannot set socket to non-blocking mode" );
} }
} }
#elif defined( HAVE_ERRNO_H ) #else
{ {
int i_flags; int i_flags;
if( ( i_flags = fcntl( i_handle, F_GETFL, 0 ) ) < 0 || if( ( i_flags = fcntl( i_handle, F_GETFL, 0 ) ) < 0 ||
...@@ -544,10 +551,8 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -544,10 +551,8 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
{ {
#if defined( WIN32 ) || defined( UNDER_CE ) #if defined( WIN32 ) || defined( UNDER_CE )
if( WSAGetLastError() == WSAEWOULDBLOCK ) if( WSAGetLastError() == WSAEWOULDBLOCK )
#elif defined( HAVE_ERRNO_H )
if( errno == EINPROGRESS )
#else #else
if( 0 ) if( errno == EINPROGRESS )
#endif #endif
{ {
int i_ret, i_opt, i_opt_size = sizeof( i_opt ), i_max_count; int i_ret, i_opt, i_opt_size = sizeof( i_opt ), i_max_count;
...@@ -586,10 +591,8 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -586,10 +591,8 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
&timeout ) ) == 0 || &timeout ) ) == 0 ||
#if defined( WIN32 ) || defined( UNDER_CE ) #if defined( WIN32 ) || defined( UNDER_CE )
( i_ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK ) ); ( i_ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK ) );
#elif defined( HAVE_ERRNO_H )
( i_ret < 0 && errno == EINTR ) );
#else #else
( i_ret < 0 ) ); ( i_ret < 0 && errno == EINTR ) );
#endif #endif
if( i_ret < 0 ) if( i_ret < 0 )
...@@ -609,10 +612,10 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -609,10 +612,10 @@ static int OpenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
} }
else else
{ {
#if defined( HAVE_ERRNO_H ) #if defined(WIN32) || defined(UNDER_CE)
msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) ); msg_Warn( p_this, "cannot connect socket (%i)", WSAGetLastError());
#else #else
msg_Warn( p_this, "cannot connect socket" ); msg_Warn( p_this, "cannot connect socket (%s)", strerror(errno) );
#endif #endif
goto error; goto error;
} }
...@@ -662,10 +665,10 @@ static int ListenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -662,10 +665,10 @@ static int ListenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
/* Bind the socket */ /* Bind the socket */
if( bind( i_handle, (struct sockaddr *) &sock, sizeof( sock )) == -1 ) if( bind( i_handle, (struct sockaddr *) &sock, sizeof( sock )) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) ); msg_Err( p_this, "cannot bind socket (%i)", WSAGetLastError());
#else #else
msg_Err( p_this, "cannot bind socket" ); msg_Err( p_this, "cannot bind socket (%s)", strerror(errno) );
#endif #endif
goto error; goto error;
} }
...@@ -673,11 +676,12 @@ static int ListenTCP( vlc_object_t * p_this, network_socket_t * p_socket ) ...@@ -673,11 +676,12 @@ static int ListenTCP( vlc_object_t * p_this, network_socket_t * p_socket )
/* Listen */ /* Listen */
if( listen( i_handle, 100 ) == -1 ) if( listen( i_handle, 100 ) == -1 )
{ {
#ifdef HAVE_ERRNO_H #if defined(WIN32) || defined(UNDER_CE)
msg_Err( p_this, "cannot bring socket in listening mode (%i)",
WSAGetLastError());
#else
msg_Err( p_this, "cannot bring the socket in listening mode (%s)", msg_Err( p_this, "cannot bring the socket in listening mode (%s)",
strerror(errno) ); strerror(errno) );
#else
msg_Err( p_this, "cannot bring the socket in listening mode" );
#endif #endif
goto error; goto error;
} }
......
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