[enet-cvs] CVS: enet protocol.c,1.5,1.6
Lee Salzman
enet-discuss@lists.puremagic.com
Sat, 12 Oct 2002 19:00:10 -0600
Update of /home/enet/cvsroot/enet
In directory sferik:/tmp/cvs-serv15590
Modified Files:
protocol.c
Log Message:
Modified to use overflow resistant time comparison macros.
Index: protocol.c
===================================================================
RCS file: /home/enet/cvsroot/enet/protocol.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- protocol.c 2002/07/28 21:26:06 1.5
+++ protocol.c 2002/10/13 01:00:08 1.6
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <enet/memory.h>
+#include <enet/time.h>
#include <enet/enet.h>
static uint32 timeCurrent;
@@ -364,12 +365,12 @@
receivedSentTime = ENET_NET_TO_HOST_32 (command -> acknowledge.receivedSentTime);
- if (timeCurrent < receivedSentTime)
+ if (ENET_TIME_LESS (timeCurrent, receivedSentTime))
return 0;
peer -> lastReceiveTime = timeCurrent;
- roundTripTime = timeCurrent - receivedSentTime;
+ roundTripTime = ENET_TIME_DIFFERENCE (timeCurrent, receivedSentTime);
peer -> roundTripTimeVariance -= peer -> roundTripTimeVariance / 4;
@@ -385,7 +386,7 @@
}
if (peer -> packetThrottleEpoch == 0 ||
- timeCurrent - peer -> packetThrottleEpoch >= peer -> packetThrottleInterval)
+ ENET_TIME_DIFFERENCE(timeCurrent, peer -> packetThrottleEpoch) >= peer -> packetThrottleInterval)
{
peer -> bestRoundTripTime = peer -> roundTripTime;
peer -> packetThrottleEpoch = timeCurrent;
@@ -783,7 +784,7 @@
currentCommand = enet_list_next (currentCommand);
- if (timeCurrent - outgoingCommand -> sentTime < outgoingCommand -> roundTripTimeout)
+ if (ENET_TIME_DIFFERENCE (timeCurrent, outgoingCommand -> sentTime) < outgoingCommand -> roundTripTimeout)
continue;
if (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit)
@@ -925,7 +926,7 @@
{
if (checkForTimeouts != 0 &&
enet_list_empty (& currentPeer -> sentReliableCommands) == 0 &&
- timeCurrent >= currentPeer -> nextTimeout &&
+ ENET_TIME_GREATER_EQUAL (timeCurrent, currentPeer -> nextTimeout) &&
enet_protocol_check_timeouts (host, currentPeer, event) == 1)
return 1;
@@ -933,7 +934,7 @@
enet_protocol_send_reliable_outgoing_commands (host, currentPeer);
else
if (enet_list_empty (& currentPeer -> sentReliableCommands) &&
- timeCurrent - currentPeer -> lastReceiveTime >= ENET_PEER_PING_INTERVAL &&
+ ENET_TIME_DIFFERENCE (timeCurrent, currentPeer -> lastReceiveTime) >= ENET_PEER_PING_INTERVAL &&
currentPeer -> packetSize - host -> packetSize >= sizeof (ENetProtocolPing))
{
enet_peer_ping (currentPeer);
@@ -951,7 +952,7 @@
if (currentPeer -> packetLossEpoch == 0)
currentPeer -> packetLossEpoch = timeCurrent;
else
- if (timeCurrent - currentPeer -> packetLossEpoch >= ENET_PEER_PACKET_LOSS_INTERVAL &&
+ if (ENET_TIME_DIFFERENCE (timeCurrent, currentPeer -> packetLossEpoch) >= ENET_PEER_PACKET_LOSS_INTERVAL &&
currentPeer -> packetsSent > 0)
{
uint32 packetLoss = currentPeer -> packetsLost * ENET_PEER_PACKET_LOSS_SCALE / currentPeer -> packetsSent;
@@ -1039,7 +1040,7 @@
do
{
- if (timeCurrent - host -> bandwidthThrottleEpoch >= ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL)
+ if (ENET_TIME_DIFFERENCE (timeCurrent, host -> bandwidthThrottleEpoch) >= ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL)
enet_host_bandwidth_throttle (host);
switch (enet_protocol_receive_incoming_commands (host, event))
@@ -1086,12 +1087,12 @@
timeCurrent = enet_time_get ();
- if (timeCurrent >= timeout)
+ if (ENET_TIME_GREATER_EQUAL (timeCurrent, timeout))
return 0;
waitCondition = ENET_SOCKET_WAIT_RECEIVE;
- if (enet_socket_wait (host -> socket, & waitCondition, timeout - timeCurrent) != 0)
+ if (enet_socket_wait (host -> socket, & waitCondition, ENET_TIME_DIFFERENCE (timeout, timeCurrent)) != 0)
return -1;
timeCurrent = enet_time_get ();