engine: common: make use NET_MakeSocketNonBlocking instead of direct system API functions

This commit is contained in:
SNMetamorph
2026-05-01 14:07:08 +04:00
committed by a1batross
parent 653fe51fd4
commit 2635fd9739
2 changed files with 12 additions and 30 deletions

View File

@@ -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;

View File

@@ -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;