mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-24 05:11:08 +00:00
Fix crash if a packet fails to reach the client
This commit is contained in:
parent
9ff0bea92c
commit
cae93e3108
1 changed files with 20 additions and 12 deletions
|
@ -87,6 +87,10 @@
|
|||
#undef EHOSTUNREACH
|
||||
#endif
|
||||
#define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#ifdef ENETUNREACH
|
||||
#undef ENETUNREACH
|
||||
#endif
|
||||
#define ENETUNREACH WSAENETUNREACH
|
||||
#ifndef IOC_VENDOR
|
||||
#define IOC_VENDOR 0x18000000
|
||||
#endif
|
||||
|
@ -681,7 +685,6 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr
|
|||
socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
socklen_t d, da = (socklen_t)sizeof(mysockaddr_t);
|
||||
ssize_t status;
|
||||
|
||||
switch (sockaddr->any.sa_family)
|
||||
{
|
||||
|
@ -692,14 +695,11 @@ static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr
|
|||
default: d = da; break;
|
||||
}
|
||||
|
||||
status = sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d);
|
||||
if (status == -1)
|
||||
{
|
||||
CONS_Alert(CONS_WARNING, "Unable to send packet to %s: %s\n", SOCK_AddrToStr(sockaddr), strerror(errno));
|
||||
}
|
||||
return status;
|
||||
return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d);
|
||||
}
|
||||
|
||||
#define ALLOWEDERROR(x) ((x) == ECONNREFUSED || (x) == EWOULDBLOCK || (x) == EHOSTUNREACH || (x) == ENETUNREACH)
|
||||
|
||||
static void SOCK_Send(void)
|
||||
{
|
||||
ssize_t c = ERRSOCKET;
|
||||
|
@ -714,19 +714,25 @@ static void SOCK_Send(void)
|
|||
for (size_t j = 0; j < broadcastaddresses; j++)
|
||||
{
|
||||
if (myfamily[i] == broadcastaddress[j].any.sa_family)
|
||||
SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]);
|
||||
{
|
||||
c = SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]);
|
||||
if (c == ERRSOCKET && !ALLOWEDERROR(errno))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (nodesocket[doomcom->remotenode] == (SOCKET_TYPE)ERRSOCKET)
|
||||
{
|
||||
for (size_t i = 0; i < mysocketses; i++)
|
||||
{
|
||||
if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family)
|
||||
SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]);
|
||||
{
|
||||
c = SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]);
|
||||
if (c == ERRSOCKET && !ALLOWEDERROR(errno))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -736,12 +742,14 @@ static void SOCK_Send(void)
|
|||
if (c == ERRSOCKET)
|
||||
{
|
||||
int e = errno; // save error code so it can't be modified later
|
||||
if (e != ECONNREFUSED && e != EWOULDBLOCK && e != EHOSTUNREACH)
|
||||
if (!ALLOWEDERROR(e))
|
||||
I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode,
|
||||
SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e));
|
||||
}
|
||||
}
|
||||
|
||||
#undef ALLOWEDERROR
|
||||
|
||||
static void SOCK_FreeNodenum(INT32 numnode)
|
||||
{
|
||||
// can't disconnect from self :)
|
||||
|
|
Loading…
Reference in a new issue