Skip to content

Commit

Permalink
Fix waking early to send pings
Browse files Browse the repository at this point in the history
  • Loading branch information
cgutman committed Oct 20, 2024
1 parent b757dc7 commit badcd6c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,17 @@ enet_protocol_compute_wait_timeout(ENetHost * host, enet_uint32 timeout)
{
if (! ENET_TIME_LESS (currentPeer -> nextTimeout, host -> serviceTime)) {
timeout = ENET_MIN (timeout, ENET_TIME_DIFFERENCE (currentPeer -> nextTimeout, host -> serviceTime) + 1);
}

if (currentPeer -> lastReceiveTime) {
enet_uint32 timeSinceLastRecv = ENET_TIME_DIFFERENCE (host -> serviceTime, currentPeer -> lastReceiveTime);
if (timeSinceLastRecv >= currentPeer -> pingInterval) {
// Ping is due now for this peer
return 0;
} else {
timeout = ENET_MIN (timeout, currentPeer -> pingInterval - timeSinceLastRecv);
}
} else {
timeout = ENET_MIN (timeout, currentPeer -> pingInterval);
}
}
Expand Down

0 comments on commit badcd6c

Please sign in to comment.