mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-18 15:32:10 +00:00
Merge branch 'netcode-nitpicking' into 'next'
Netcode nitpicking See merge request STJr/SRB2!274
This commit is contained in:
commit
316c08bbbb
1 changed files with 26 additions and 42 deletions
68
src/i_tcp.c
68
src/i_tcp.c
|
@ -686,14 +686,29 @@ static boolean SOCK_CanGet(void)
|
|||
#endif
|
||||
|
||||
#ifndef NONET
|
||||
static void SOCK_Send(void)
|
||||
static inline ssize_t SOCK_SendToAddr(SOCKET_TYPE socket, mysockaddr_t *sockaddr)
|
||||
{
|
||||
ssize_t c = ERRSOCKET;
|
||||
socklen_t d4 = (socklen_t)sizeof(struct sockaddr_in);
|
||||
#ifdef HAVE_IPV6
|
||||
socklen_t d6 = (socklen_t)sizeof(struct sockaddr_in6);
|
||||
#endif
|
||||
socklen_t d, da = (socklen_t)sizeof(mysockaddr_t);
|
||||
|
||||
switch (sockaddr->any.sa_family)
|
||||
{
|
||||
case AF_INET: d = d4; break;
|
||||
#ifdef HAVE_IPV6
|
||||
case AF_INET6: d = d6; break;
|
||||
#endif
|
||||
default: d = da; break;
|
||||
}
|
||||
|
||||
return sendto(socket, (char *)&doomcom->data, doomcom->datalength, 0, &sockaddr->any, d);
|
||||
}
|
||||
|
||||
static void SOCK_Send(void)
|
||||
{
|
||||
ssize_t c = ERRSOCKET;
|
||||
size_t i, j;
|
||||
|
||||
if (!nodeconnected[doomcom->remotenode])
|
||||
|
@ -706,19 +721,7 @@ static void SOCK_Send(void)
|
|||
for (j = 0; j < broadcastaddresses; j++)
|
||||
{
|
||||
if (myfamily[i] == broadcastaddress[j].any.sa_family)
|
||||
{
|
||||
if (broadcastaddress[i].any.sa_family == AF_INET)
|
||||
d = d4;
|
||||
#ifdef HAVE_IPV6
|
||||
else if (broadcastaddress[i].any.sa_family == AF_INET6)
|
||||
d = d6;
|
||||
#endif
|
||||
else
|
||||
d = da;
|
||||
|
||||
c = sendto(mysockets[i], (char *)&doomcom->data, doomcom->datalength, 0,
|
||||
&broadcastaddress[j].any, d);
|
||||
}
|
||||
SOCK_SendToAddr(mysockets[i], &broadcastaddress[j]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -728,35 +731,13 @@ static void SOCK_Send(void)
|
|||
for (i = 0; i < mysocketses; i++)
|
||||
{
|
||||
if (myfamily[i] == clientaddress[doomcom->remotenode].any.sa_family)
|
||||
{
|
||||
if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET)
|
||||
d = d4;
|
||||
#ifdef HAVE_IPV6
|
||||
else if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET6)
|
||||
d = d6;
|
||||
#endif
|
||||
else
|
||||
d = da;
|
||||
|
||||
sendto(mysockets[i], (char *)&doomcom->data, doomcom->datalength, 0,
|
||||
&clientaddress[doomcom->remotenode].any, d);
|
||||
}
|
||||
SOCK_SendToAddr(mysockets[i], &clientaddress[doomcom->remotenode]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET)
|
||||
d = d4;
|
||||
#ifdef HAVE_IPV6
|
||||
else if (clientaddress[doomcom->remotenode].any.sa_family == AF_INET6)
|
||||
d = d6;
|
||||
#endif
|
||||
else
|
||||
d = da;
|
||||
|
||||
c = sendto(nodesocket[doomcom->remotenode], (char *)&doomcom->data, doomcom->datalength, 0,
|
||||
&clientaddress[doomcom->remotenode].any, d);
|
||||
c = SOCK_SendToAddr(nodesocket[doomcom->remotenode], &clientaddress[doomcom->remotenode]);
|
||||
}
|
||||
|
||||
if (c == ERRSOCKET && errno != ECONNREFUSED && errno != EWOULDBLOCK)
|
||||
|
@ -1044,7 +1025,7 @@ static boolean UDP_Socket(void)
|
|||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
while (runp != NULL)
|
||||
while (runp != NULL && s < MAXNETNODES+1)
|
||||
{
|
||||
memcpy(&clientaddress[s], runp->ai_addr, runp->ai_addrlen);
|
||||
s++;
|
||||
|
@ -1059,12 +1040,15 @@ static boolean UDP_Socket(void)
|
|||
clientaddress[s].ip4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); //GetLocalAddress(); // my own ip
|
||||
s++;
|
||||
}
|
||||
|
||||
s = 0;
|
||||
|
||||
// setup broadcast adress to BROADCASTADDR entry
|
||||
gaie = I_getaddrinfo("255.255.255.255", "0", &hints, &ai);
|
||||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
while (runp != NULL)
|
||||
while (runp != NULL && s < MAXNETNODES+1)
|
||||
{
|
||||
memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen);
|
||||
s++;
|
||||
|
@ -1087,7 +1071,7 @@ static boolean UDP_Socket(void)
|
|||
if (gaie == 0)
|
||||
{
|
||||
runp = ai;
|
||||
while (runp != NULL)
|
||||
while (runp != NULL && s < MAXNETNODES+1)
|
||||
{
|
||||
memcpy(&broadcastaddress[s], runp->ai_addr, runp->ai_addrlen);
|
||||
s++;
|
||||
|
|
Loading…
Reference in a new issue