mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: common: make use NET_MakeSocketNonBlocking instead of direct system API functions
This commit is contained in:
@@ -249,9 +249,6 @@ static int HTTP_FileResolveNS( httpfile_t *file )
|
||||
|
||||
static int HTTP_FileCreateSocket( httpfile_t *file )
|
||||
{
|
||||
uint mode = 1;
|
||||
int res;
|
||||
|
||||
file->socket = socket( file->addr.ss_family, SOCK_STREAM, IPPROTO_TCP );
|
||||
|
||||
if( file->socket < 0 )
|
||||
@@ -261,33 +258,13 @@ static int HTTP_FileCreateSocket( httpfile_t *file )
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( ioctlsocket( file->socket, FIONBIO, (void *)&mode ) < 0 )
|
||||
if( !NET_MakeSocketNonBlocking( file->socket ))
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: ioctl() returned %s\n", __func__, NET_ErrorString());
|
||||
Con_Printf( S_ERROR "%s: failed to make socket non-blocking, error %s\n", __func__, NET_ErrorString());
|
||||
HTTP_FreeFile( file, true );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if XASH_LINUX
|
||||
|
||||
res = fcntl( file->socket, F_GETFL, 0 );
|
||||
|
||||
if( res < 0 )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: fcntl( F_GETFL ) returned %s\n", __func__, NET_ErrorString());
|
||||
HTTP_FreeFile( file, true );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// SOCK_NONBLOCK is not portable, so use fcntl
|
||||
if( fcntl( file->socket, F_SETFL, res | O_NONBLOCK ) < 0 )
|
||||
{
|
||||
Con_Printf( S_ERROR "%s: fcntl( F_SETFL ) returned %s\n", __func__, NET_ErrorString());
|
||||
HTTP_FreeFile( file, true );
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
http.active_count++;
|
||||
file->pfn_process = HTTP_FileConnect;
|
||||
return 1;
|
||||
|
||||
@@ -152,12 +152,17 @@ qboolean NET_IsSocketValid( int socket )
|
||||
|
||||
qboolean NET_MakeSocketNonBlocking( int socket_fd )
|
||||
{
|
||||
#if XASH_WIN32 || XASH_PSVITA
|
||||
u_long flag = 1;
|
||||
if( NET_IsSocketError( ioctlsocket( socket_fd, FIONBIO, &flag )))
|
||||
#if XASH_LINUX
|
||||
int res = fcntl( socket_fd, F_GETFL, 0 );
|
||||
if( NET_IsSocketError( res ))
|
||||
return false;
|
||||
|
||||
// SOCK_NONBLOCK is not portable, so use fcntl
|
||||
if( NET_IsSocketError( fcntl( socket_fd, F_SETFL, res | O_NONBLOCK )))
|
||||
return false;
|
||||
#else
|
||||
if( NET_IsSocketError( fcntl( socket_fd, F_SETFL, O_NONBLOCK )))
|
||||
uint mode = 1;
|
||||
if( NET_IsSocketError( ioctlsocket( socket_fd, FIONBIO, (void*)&mode )))
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
@@ -1604,7 +1609,7 @@ static int NET_IPSocket( const char *net_iface, int port, int family )
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if( NET_IsSocketError( ioctlsocket( net_socket, FIONBIO, (void*)&_true )))
|
||||
if( !NET_MakeSocketNonBlocking( net_socket ))
|
||||
{
|
||||
struct timeval timeout;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user