@ -17,7 +17,7 @@ GNU General Public License for more details.
# include "client.h" // ConnectionProgress
# include "client.h" // ConnectionProgress
# include "netchan.h"
# include "netchan.h"
# include "mathlib.h"
# include "mathlib.h"
# ifdef _WIN32
# if XASH _WIN32
// Winsock
// Winsock
# include <WS2tcpip.h>
# include <WS2tcpip.h>
# else
# else
@ -44,7 +44,7 @@ GNU General Public License for more details.
# define SPLITPACKET_MAX_SIZE 64000
# define SPLITPACKET_MAX_SIZE 64000
# define NET_MAX_FRAGMENTS ( NET_MAX_FRAGMENT / (SPLITPACKET_MIN_SIZE - sizeof( SPLITPACKET )) )
# define NET_MAX_FRAGMENTS ( NET_MAX_FRAGMENT / (SPLITPACKET_MIN_SIZE - sizeof( SPLITPACKET )) )
# ifndef _WIN32 // not available in XP
# if !XASH _WIN32 // not available in XP
# define HAVE_GETADDRINFO
# define HAVE_GETADDRINFO
# define WSAGetLastError() errno
# define WSAGetLastError() errno
# define WSAEINTR EINTR
# define WSAEINTR EINTR
@ -84,16 +84,16 @@ GNU General Public License for more details.
# define WSAENAMETOOLONG ENAMETOOLONG
# define WSAENAMETOOLONG ENAMETOOLONG
# define WSAEHOSTDOWN EHOSTDOWN
# define WSAEHOSTDOWN EHOSTDOWN
# ifdef __EMSCRIPTEN__
# if XASH_EMSCRIPTEN
/* All socket operations are non-blocking already */
/* All socket operations are non-blocking already */
static int ioctl_stub ( int d , unsigned long r , . . . )
static int ioctl_stub ( int d , unsigned long r , . . . )
{
{
return 0 ;
return 0 ;
}
}
# define ioctlsocket ioctl_stub
# define ioctlsocket ioctl_stub
# else // __EMSCRIPTEN__
# else // XASH_EMSCRIPTEN
# define ioctlsocket ioctl
# define ioctlsocket ioctl
# endif // __EMSCRIPTEN__
# endif // XASH_EMSCRIPTEN
# define closesocket close
# define closesocket close
# define SOCKET int
# define SOCKET int
# define INVALID_SOCKET -1
# define INVALID_SOCKET -1
@ -157,7 +157,7 @@ typedef struct
qboolean threads_initialized ;
qboolean threads_initialized ;
qboolean configured ;
qboolean configured ;
qboolean allow_ip ;
qboolean allow_ip ;
# ifdef _WIN32
# if XASH _WIN32
WSADATA winsockdata ;
WSADATA winsockdata ;
# endif
# endif
} net_state_t ;
} net_state_t ;
@ -181,7 +181,7 @@ NET_ErrorString
*/
*/
char * NET_ErrorString ( void )
char * NET_ErrorString ( void )
{
{
# ifdef _WIN32
# if XASH _WIN32
int err = WSANOTINITIALISED ;
int err = WSANOTINITIALISED ;
if ( net . initialized )
if ( net . initialized )
@ -242,7 +242,7 @@ char *NET_ErrorString( void )
_inline qboolean NET_IsSocketError ( int retval )
_inline qboolean NET_IsSocketError ( int retval )
{
{
# ifdef _WIN32
# if XASH _WIN32
return retval = = SOCKET_ERROR ? true : false ;
return retval = = SOCKET_ERROR ? true : false ;
# else
# else
return retval < 0 ? true : false ;
return retval < 0 ? true : false ;
@ -251,7 +251,7 @@ _inline qboolean NET_IsSocketError( int retval )
_inline qboolean NET_IsSocketValid ( int socket )
_inline qboolean NET_IsSocketValid ( int socket )
{
{
# ifdef _WIN32
# if XASH _WIN32
return socket ! = INVALID_SOCKET ;
return socket ! = INVALID_SOCKET ;
# else
# else
return socket > = 0 ;
return socket > = 0 ;
@ -335,14 +335,14 @@ int NET_GetHostByName( const char *hostname )
# endif
# endif
}
}
# if !defined XASH_NO_ASYNC_NS_RESOLVE && ( defined _WIN32 || !defined __EMSCRIPTEN__ )
# if !defined XASH_NO_ASYNC_NS_RESOLVE && ( XASH_WIN32 || !XASH_EMSCRIPTEN )
# define CAN_ASYNC_NS_RESOLVE
# define CAN_ASYNC_NS_RESOLVE
# endif
# endif
# ifdef CAN_ASYNC_NS_RESOLVE
# ifdef CAN_ASYNC_NS_RESOLVE
static void NET_ResolveThread ( void ) ;
static void NET_ResolveThread ( void ) ;
# if !defined _WIN32
# if !XASH _WIN32
# include <pthread.h>
# include <pthread.h>
# define mutex_lock pthread_mutex_lock
# define mutex_lock pthread_mutex_lock
# define mutex_unlock pthread_mutex_unlock
# define mutex_unlock pthread_mutex_unlock
@ -386,12 +386,12 @@ static struct nsthread_s
string hostname ;
string hostname ;
qboolean busy ;
qboolean busy ;
} nsthread
} nsthread
# ifndef _WIN32
# if !XASH _WIN32
= { PTHREAD_MUTEX_INITIALIZER , PTHREAD_MUTEX_INITIALIZER }
= { PTHREAD_MUTEX_INITIALIZER , PTHREAD_MUTEX_INITIALIZER }
# endif
# endif
;
;
# ifdef _WIN32
# if XASH _WIN32
static void NET_InitializeCriticalSections ( void )
static void NET_InitializeCriticalSections ( void )
{
{
net . threads_initialized = true ;
net . threads_initialized = true ;
@ -1107,7 +1107,7 @@ qboolean NET_QueuePacket( netsrc_t sock, netadr_t *from, byte *data, size_t *len
// Transfer data
// Transfer data
memcpy ( data , buf , ret ) ;
memcpy ( data , buf , ret ) ;
* length = ret ;
* length = ret ;
# ifndef XASH_DEDICATED
# if ! XASH_DEDICATED
if ( CL_LegacyMode ( ) )
if ( CL_LegacyMode ( ) )
return NET_LagPacket ( true , sock , from , length , data ) ;
return NET_LagPacket ( true , sock , from , length , data ) ;
@ -1702,7 +1702,7 @@ void NET_Init( void )
net . ip_sockets [ i ] = INVALID_SOCKET ;
net . ip_sockets [ i ] = INVALID_SOCKET ;
}
}
# ifdef _WIN32
# if XASH _WIN32
if ( WSAStartup ( MAKEWORD ( 1 , 1 ) , & net . winsockdata ) )
if ( WSAStartup ( MAKEWORD ( 1 , 1 ) , & net . winsockdata ) )
{
{
Con_DPrintf ( S_ERROR " network initialization failed. \n " ) ;
Con_DPrintf ( S_ERROR " network initialization failed. \n " ) ;
@ -1748,7 +1748,7 @@ void NET_Shutdown( void )
NET_ClearLagData ( true , true ) ;
NET_ClearLagData ( true , true ) ;
NET_Config ( false ) ;
NET_Config ( false ) ;
# ifdef _WIN32
# if XASH _WIN32
WSACleanup ( ) ;
WSACleanup ( ) ;
# endif
# endif
net . initialized = false ;
net . initialized = false ;
@ -2137,7 +2137,7 @@ void HTTP_Run( void )
// but download will lock engine, maybe you will need to add manual returns
// but download will lock engine, maybe you will need to add manual returns
mode = 1 ;
mode = 1 ;
ioctlsocket ( curfile - > socket , FIONBIO , & mode ) ;
ioctlsocket ( curfile - > socket , FIONBIO , & mode ) ;
# ifdef __linux__
# if XASH_LINUX
// SOCK_NONBLOCK is not portable, so use fcntl
// SOCK_NONBLOCK is not portable, so use fcntl
fcntl ( curfile - > socket , F_SETFL , fcntl ( curfile - > socket , F_GETFL , 0 ) | O_NONBLOCK ) ;
fcntl ( curfile - > socket , F_SETFL , fcntl ( curfile - > socket , F_GETFL , 0 ) | O_NONBLOCK ) ;
# endif
# endif