diff --git a/engine/common/http/net_http_xash.c b/engine/common/http/net_http_xash.c index 4ad8f033..24f8156e 100644 --- a/engine/common/http/net_http_xash.c +++ b/engine/common/http/net_http_xash.c @@ -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; diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index 5c607923..7f4e2830 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -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;