From 40e29b0c3993eee256129f0916c00f4666a6f7b1 Mon Sep 17 00:00:00 2001 From: Florian Schulze Date: Sun, 18 Aug 2002 20:05:54 +0000 Subject: [PATCH] Buffer packets if not completly received. --- main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e07e82c..b738f79 100644 --- a/main.c +++ b/main.c @@ -363,17 +363,19 @@ void sendPacketToAll(NetPacket *pkt) int grabPacket(TCPsocket s, SDLNet_SocketSet ss, NetPacket *pkt) { - char buf[NETPKTBUFSIZE]; + static char buf[NETPKTBUFSIZE]; + static int buf_count = 0; int rc; int retval = 0; if (SDLNet_CheckSockets(ss, 0) > 0) { - rc = SDLNet_TCP_Recv(s, buf, NETPKTBUFSIZE); + rc = SDLNet_TCP_Recv(s, &buf[buf_count], NETPKTBUFSIZE - buf_count); if (rc <= 0) { /* closed connection? */ retval = -1; } else if (rc != NETPKTBUFSIZE) { // !!! FIXME: buffer these? - printf("NETWORK: -BUG- ... dropped a packet! (had %d of %d bytes).\b", rc, NETPKTBUFSIZE); + buf_count = rc; } else { + buf_count = 0; bufToPacket(buf, pkt); retval = 1; } -- 2.39.2