https://github.com/libsdl-org/Maelstrom/commit/71adc6ad886f154ad5775aa6dc1865706d9db709
From 71adc6ad886f154ad5775aa6dc1865706d9db709 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 7 Nov 2011 21:50:32 -0500
Subject: [PATCH] Wait a much shorter time for packets, since we're supposed to
be playing with <50ms latency, and then timeout the game after PING_TIMEOUT
has been exceeded.
---
netlogic/netplay.cpp | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/netlogic/netplay.cpp b/netlogic/netplay.cpp
index 6145da7c..77c471a2 100644
--- a/netlogic/netplay.cpp
+++ b/netlogic/netplay.cpp
@@ -238,6 +238,7 @@ int SyncNetwork(void)
Uint32 seed, frame;
unsigned char buf[BUFSIZ];
int index, nleft;
+ int timeout;
/* Set the next inbound packet buffer */
TOGGLE(CurrIn);
@@ -262,16 +263,28 @@ int SyncNetwork(void)
sent.maxlen = sizeof(buf);
/* Wait for Ack's */
+ timeout = 0;
while ( nleft ) {
- int ready = SDLNet_CheckSockets(SocketSet, 1000+60*gOurPlayer);
+ int ready = SDLNet_CheckSockets(SocketSet, 100);
+ if ( ready < 0 ) {
+ error("Network error: SDLNet_CheckSockets()");
+ return(-1);
+ }
if ( ready == 0 ) {
-error("Timed out waiting for frame %ld\r\n", NextFrame);
+ error("Timed out waiting for frame %ld\r\n", NextFrame);
+
/* Timeout, resend the sync packet */
for ( index=0; index<gNumPlayers; ++index ) {
if ( SyncPtr[index] == NULL ) {
SDLNet_UDP_Send(gNetFD, index+1, OutBound[CurrOut]);
}
}
+
+ /* Don't wait forever */
+ ++timeout;
+ if ( timeout == (PING_TIMEOUT/100) ) {
+ return(-1);
+ }
}
if ( ready <= 0 ) {
continue;