X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=lhnet.c;h=d6372548ce3c649d84d8c06414339ace6fe08fdf;hb=670fff8d7da36276013d5052d1167b52c417e677;hp=3854e2d4731aa738f3ae1d49e75368ea67c2fcc3;hpb=7cfe479b525e263940751490b4fa600ebb4e9341;p=xonotic%2Fdarkplaces.git diff --git a/lhnet.c b/lhnet.c index 3854e2d4..d6372548 100644 --- a/lhnet.c +++ b/lhnet.c @@ -19,7 +19,10 @@ // for Z_Malloc/Z_Free in quake #ifndef STANDALONETEST +#include "quakedef.h" #include "zone.h" +#include "sys.h" +#include "netconn.h" #else #define Z_Malloc malloc #define Z_Free free @@ -296,6 +299,9 @@ typedef struct lhnetpacket_s int sourceport; int destinationport; time_t timeout; +#ifndef STANDALONETEST + double sentdoubletime; +#endif struct lhnetpacket_s *next, *prev; } lhnetpacket_t; @@ -481,6 +487,18 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, for (p = lhnet_packetlist.next;p != &lhnet_packetlist;p = pnext) { pnext = p->next; + if (p->timeout < currenttime) + { + // unlink and free + p->next->prev = p->prev; + p->prev->next = p->next; + Z_Free(p); + continue; + } +#ifndef STANDALONETEST + if (p->sentdoubletime && Sys_DoubleTime() < p->sentdoubletime) + continue; +#endif if (value == 0 && p->destinationport == lhnetsocket->address.addressdata.loop.port) { if (p->length <= maxcontentlength) @@ -497,13 +515,6 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, p->prev->next = p->next; Z_Free(p); } - else if (p->timeout < currenttime) - { - // unlink and free - p->next->prev = p->prev; - p->prev->next = p->next; - Z_Free(p); - } } } else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4) @@ -521,11 +532,23 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, { #ifdef WIN32 int e = WSAGetLastError(); - if (e == WSAEWOULDBLOCK || e == WSAECONNREFUSED) + if (e == WSAEWOULDBLOCK) return 0; + switch (e) + { + case WSAECONNREFUSED: + Con_Printf("Connection refused\n"); + return 0; + } #else - if (errno == EWOULDBLOCK || errno == ECONNREFUSED) + if (errno == EWOULDBLOCK) return 0; + switch (errno) + { + case ECONNREFUSED: + Con_Printf("Connection refused\n"); + return 0; + } #endif } } @@ -544,11 +567,23 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, { #ifdef WIN32 int e = WSAGetLastError(); - if (e == WSAEWOULDBLOCK || e == WSAECONNREFUSED) + if (e == WSAEWOULDBLOCK) return 0; + switch (e) + { + case WSAECONNREFUSED: + Con_Printf("Connection refused\n"); + return 0; + } #else - if (errno == EWOULDBLOCK || errno == ECONNREFUSED) + if (errno == EWOULDBLOCK) return 0; + switch (errno) + { + case ECONNREFUSED: + Con_Printf("Connection refused\n"); + return 0; + } #endif } } @@ -558,7 +593,7 @@ int LHNET_Read(lhnetsocket_t *lhnetsocket, void *content, int maxcontentlength, int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentlength, const lhnetaddress_t *address) { int value = -1; - if (!lhnetsocket || !address || !content || maxcontentlength < 1) + if (!lhnetsocket || !address || !content || contentlength < 1) return -1; if (lhnetsocket->address.addresstype != address->addresstype) return -1; @@ -576,6 +611,10 @@ int LHNET_Write(lhnetsocket_t *lhnetsocket, const void *content, int contentleng p->prev = p->next->prev; p->next->prev = p; p->prev->next = p; +#ifndef STANDALONETEST + if (cl_fakelocalping_min.integer || cl_fakelocalping_max.integer) + p->sentdoubletime = Sys_DoubleTime() + (cl_fakelocalping_min.integer + ((cl_fakelocalping_max.integer - cl_fakelocalping_min.integer) * (rand() & 255) / 256)) / 1000.0; +#endif value = contentlength; } else if (lhnetsocket->address.addresstype == LHNETADDRESSTYPE_INET4)