TCP: remove BADSOCKET

This commit is contained in:
Alam Ed Arias 2017-12-26 19:56:50 -05:00
parent 97af30ae4b
commit e2b604fdfd
5 changed files with 47 additions and 51 deletions

View file

@ -215,7 +215,6 @@ static UINT8 UPNP_support = TRUE;
#if defined (USE_WINSOCK) && !defined (NONET) #if defined (USE_WINSOCK) && !defined (NONET)
typedef SOCKET SOCKET_TYPE; typedef SOCKET SOCKET_TYPE;
#define BADSOCKET INVALID_SOCKET
#define ERRSOCKET (SOCKET_ERROR) #define ERRSOCKET (SOCKET_ERROR)
#else #else
#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined(_PS3) #if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined(_PS3)
@ -223,7 +222,6 @@ typedef int SOCKET_TYPE;
#else #else
typedef unsigned long SOCKET_TYPE; typedef unsigned long SOCKET_TYPE;
#endif #endif
#define BADSOCKET (SOCKET_TYPE)(~0)
#define ERRSOCKET (-1) #define ERRSOCKET (-1)
#endif #endif
@ -232,10 +230,10 @@ typedef int socklen_t;
#endif #endif
#ifndef NONET #ifndef NONET
static SOCKET_TYPE mysockets[MAXNETNODES+1] = {BADSOCKET}; static SOCKET_TYPE mysockets[MAXNETNODES+1] = {ERRSOCKET};
static size_t mysocketses = 0; static size_t mysocketses = 0;
static int myfamily[MAXNETNODES+1] = {0}; static int myfamily[MAXNETNODES+1] = {0};
static SOCKET_TYPE nodesocket[MAXNETNODES+1] = {BADSOCKET}; static SOCKET_TYPE nodesocket[MAXNETNODES+1] = {ERRSOCKET};
static mysockaddr_t clientaddress[MAXNETNODES+1]; static mysockaddr_t clientaddress[MAXNETNODES+1];
static mysockaddr_t broadcastaddress[MAXNETNODES+1]; static mysockaddr_t broadcastaddress[MAXNETNODES+1];
static size_t broadcastaddresses = 0; static size_t broadcastaddresses = 0;
@ -647,7 +645,7 @@ static boolean FD_CPY(fd_set *src, fd_set *dst, SOCKET_TYPE *fd, size_t len)
FD_ZERO(dst); FD_ZERO(dst);
for (i = 0; i < len;i++) for (i = 0; i < len;i++)
{ {
if(fd[i] != BADSOCKET && fd[i] != (SOCKET_TYPE)ERRSOCKET && if(fd[i] != (SOCKET_TYPE)ERRSOCKET &&
FD_ISSET(fd[i], src) && !FD_ISSET(fd[i], dst)) // no checking for dups FD_ISSET(fd[i], src) && !FD_ISSET(fd[i], dst)) // no checking for dups
{ {
FD_SET(fd[i], dst); FD_SET(fd[i], dst);
@ -725,7 +723,7 @@ static void SOCK_Send(void)
} }
return; return;
} }
else if (nodesocket[doomcom->remotenode] == BADSOCKET) else if (nodesocket[doomcom->remotenode] == (SOCKET_TYPE)ERRSOCKET)
{ {
for (i = 0; i < mysocketses; i++) for (i = 0; i < mysocketses; i++)
{ {
@ -777,7 +775,7 @@ static void SOCK_FreeNodenum(INT32 numnode)
DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode))); DEBFILE(va("Free node %d (%s)\n", numnode, SOCK_GetNodeAddress(numnode)));
nodeconnected[numnode] = false; nodeconnected[numnode] = false;
nodesocket[numnode] = BADSOCKET; nodesocket[numnode] = ERRSOCKET;
// put invalid address // put invalid address
memset(&clientaddress[numnode], 0, sizeof (clientaddress[numnode])); memset(&clientaddress[numnode], 0, sizeof (clientaddress[numnode]));
@ -804,7 +802,7 @@ static SOCKET_TYPE UDP_Bind(int family, struct sockaddr *addr, socklen_t addrlen
#endif #endif
mysockaddr_t straddr; mysockaddr_t straddr;
if (s == (SOCKET_TYPE)ERRSOCKET || s == BADSOCKET) if (s == (SOCKET_TYPE)ERRSOCKET)
return (SOCKET_TYPE)ERRSOCKET; return (SOCKET_TYPE)ERRSOCKET;
#ifdef USE_WINSOCK #ifdef USE_WINSOCK
{ // Alam_GBC: disable the new UDP connection reset behavior for Win2k and up { // Alam_GBC: disable the new UDP connection reset behavior for Win2k and up
@ -911,9 +909,9 @@ static boolean UDP_Socket(void)
for (s = 0; s < mysocketses; s++) for (s = 0; s < mysocketses; s++)
mysockets[s] = BADSOCKET; mysockets[s] = ERRSOCKET;
for (s = 0; s < MAXNETNODES+1; s++) for (s = 0; s < MAXNETNODES+1; s++)
nodesocket[s] = BADSOCKET; nodesocket[s] = ERRSOCKET;
FD_ZERO(&masterset); FD_ZERO(&masterset);
s = 0; s = 0;
@ -1250,7 +1248,6 @@ static void SOCK_CloseSocket(void)
for (i=0; i < MAXNETNODES+1; i++) for (i=0; i < MAXNETNODES+1; i++)
{ {
if (mysockets[i] != (SOCKET_TYPE)ERRSOCKET if (mysockets[i] != (SOCKET_TYPE)ERRSOCKET
&& mysockets[i] != BADSOCKET
&& FD_ISSET(mysockets[i], &masterset)) && FD_ISSET(mysockets[i], &masterset))
{ {
#if !defined (__DJGPP__) || defined (WATTCP) #if !defined (__DJGPP__) || defined (WATTCP)
@ -1258,7 +1255,7 @@ static void SOCK_CloseSocket(void)
close(mysockets[i]); close(mysockets[i]);
#endif #endif
} }
mysockets[i] = BADSOCKET; mysockets[i] = ERRSOCKET;
} }
} }
#endif #endif

View file

@ -217,7 +217,6 @@ UINT16 current_port = 0;
#if (defined (_WIN32) || defined (_WIN32_WCE) || defined (_WIN32)) && !defined (NONET) #if (defined (_WIN32) || defined (_WIN32_WCE) || defined (_WIN32)) && !defined (NONET)
typedef SOCKET SOCKET_TYPE; typedef SOCKET SOCKET_TYPE;
#define BADSOCKET INVALID_SOCKET
#define ERRSOCKET (SOCKET_ERROR) #define ERRSOCKET (SOCKET_ERROR)
#else #else
#if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined (_PS3) #if (defined (__unix__) && !defined (MSDOS)) || defined (__APPLE__) || defined (__HAIKU__) || defined (_PS3)
@ -225,7 +224,6 @@ typedef int SOCKET_TYPE;
#else #else
typedef unsigned long SOCKET_TYPE; typedef unsigned long SOCKET_TYPE;
#endif #endif
#define BADSOCKET (SOCKET_TYPE)(~0)
#define ERRSOCKET (-1) #define ERRSOCKET (-1)
#endif #endif
@ -234,7 +232,7 @@ typedef int socklen_t;
#endif #endif
#ifndef NONET #ifndef NONET
static SOCKET_TYPE socket_fd = BADSOCKET; // WINSOCK socket static SOCKET_TYPE socket_fd = ERRSOCKET; // WINSOCK socket
static struct timeval select_timeout; static struct timeval select_timeout;
static fd_set wset; static fd_set wset;
static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags); static size_t recvfull(SOCKET_TYPE s, char *buf, size_t len, int flags);
@ -265,9 +263,9 @@ void AddMServCommands(void)
static void CloseConnection(void) static void CloseConnection(void)
{ {
#ifndef NONET #ifndef NONET
if (socket_fd != (SOCKET_TYPE)ERRSOCKET && socket_fd != BADSOCKET) if (socket_fd != (SOCKET_TYPE)ERRSOCKET)
close(socket_fd); close(socket_fd);
socket_fd = BADSOCKET; socket_fd = ERRSOCKET;
#endif #endif
} }
@ -385,7 +383,7 @@ static INT32 MS_Connect(const char *ip_addr, const char *str_port, INT32 async)
while (runp != NULL) while (runp != NULL)
{ {
socket_fd = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol); socket_fd = socket(runp->ai_family, runp->ai_socktype, runp->ai_protocol);
if (socket_fd != BADSOCKET && socket_fd != (SOCKET_TYPE)ERRSOCKET) if (socket_fd != (SOCKET_TYPE)ERRSOCKET)
{ {
if (async) // do asynchronous connection if (async) // do asynchronous connection
{ {

View file

@ -244,7 +244,7 @@ static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPAR
D_PostEvent(&ev); D_PostEvent(&ev);
return TRUE; return TRUE;
} }
break;
case WM_XBUTTONDOWN: case WM_XBUTTONDOWN:
if (nodinput) if (nodinput)
{ {
@ -253,7 +253,7 @@ static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPAR
D_PostEvent(&ev); D_PostEvent(&ev);
return TRUE; return TRUE;
} }
break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
//I_OutputMsg("MW_WHEEL dispatched.\n"); //I_OutputMsg("MW_WHEEL dispatched.\n");
ev.type = ev_keydown; ev.type = ev_keydown;

View file

@ -2581,7 +2581,7 @@ acquire:
UINT64 newbuttons = joybuttons ^ lastjoybuttons; UINT64 newbuttons = joybuttons ^ lastjoybuttons;
lastjoybuttons = joybuttons; lastjoybuttons = joybuttons;
for (i = 0; i < JOYBUTTONS && i < JOYBUTTONS_MAX; i++, j <<= 1) for (i = 0; i < JOYBUTTONS_MIN; i++, j <<= 1)
{ {
if (newbuttons & j) // button changed state? if (newbuttons & j) // button changed state?
{ {
@ -2601,7 +2601,7 @@ acquire:
UINT64 newhats = joyhats ^ lastjoyhats; UINT64 newhats = joyhats ^ lastjoyhats;
lastjoyhats = joyhats; lastjoyhats = joyhats;
for (i = 0; i < JOYHATS*4 && i < JOYHATS_MAX*4; i++, j <<= 1) for (i = 0; i < JOYHATS_MIN*4; i++, j <<= 1)
{ {
if (newhats & j) // button changed state? if (newhats & j) // button changed state?
{ {
@ -2825,7 +2825,7 @@ acquire:
UINT64 newbuttons = joybuttons ^ lastjoy2buttons; UINT64 newbuttons = joybuttons ^ lastjoy2buttons;
lastjoy2buttons = joybuttons; lastjoy2buttons = joybuttons;
for (i = 0; i < JOYBUTTONS && i < JOYBUTTONS_MAX; i++, j <<= 1) for (i = 0; i < JOYBUTTONS_MIN; i++, j <<= 1)
{ {
if (newbuttons & j) // button changed state? if (newbuttons & j) // button changed state?
{ {
@ -2845,7 +2845,7 @@ acquire:
UINT64 newhats = joyhats ^ lastjoy2hats; UINT64 newhats = joyhats ^ lastjoy2hats;
lastjoy2hats = joyhats; lastjoy2hats = joyhats;
for (i = 0; i < JOYHATS*4 && i < JOYHATS_MAX*4; i++, j <<= 1) for (i = 0; i < JOYHATS_MIN*4; i++, j <<= 1)
{ {
if (newhats & j) // button changed state? if (newhats & j) // button changed state?
{ {

View file

@ -322,6 +322,7 @@ static inline boolean I_SkipFrame(void)
case GS_LEVEL: case GS_LEVEL:
if (!paused) if (!paused)
return false; return false;
/* FALLTHRU */
case GS_TIMEATTACK: case GS_TIMEATTACK:
#ifndef CLIENT_LOADINGSCREEN #ifndef CLIENT_LOADINGSCREEN
case GS_WAITINGPLAYERS: case GS_WAITINGPLAYERS: