summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlsalzman <[email protected]>2013-05-08 11:02:13 +0300
committerlsalzman <[email protected]>2013-05-08 11:02:13 +0300
commit71d6d63ed852eb011fba7bf568ab2ce478f5a2ac (patch)
treef2c78e4c0c15e6166771f91b77b26968eeebc87a
parent30d859f9a42900e0717166caefe7986f0e0a75c3 (diff)
downloadenet-71d6d63ed852eb011fba7bf568ab2ce478f5a2ac.tar.gz
enet-71d6d63ed852eb011fba7bf568ab2ce478f5a2ac.zip
remove some more looping in enet_host_bandwidth_throttle
-rw-r--r--host.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/host.c b/host.c
index a95fed6..43c6f75 100644
--- a/host.c
+++ b/host.c
@@ -367,11 +367,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
else
bandwidth = (host -> outgoingBandwidth * elapsedTime) / 1000;
- if (dataTotal < bandwidth)
- throttle = ENET_PEER_PACKET_THROTTLE_SCALE;
- else
- throttle = (bandwidth * ENET_PEER_PACKET_THROTTLE_SCALE) / dataTotal;
-
while (peersRemaining > 0 && needsAdjustment != 0)
{
needsAdjustment = 0;
@@ -407,6 +402,9 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer -> outgoingBandwidthThrottleEpoch = timeCurrent;
+ peer -> incomingDataTotal = 0;
+ peer -> outgoingDataTotal = 0;
+
needsAdjustment = 1;
-- peersRemaining;
bandwidth -= peerBandwidth;
@@ -415,20 +413,30 @@ enet_host_bandwidth_throttle (ENetHost * host)
}
if (peersRemaining > 0)
- for (peer = host -> peers;
- peer < & host -> peers [host -> peerCount];
- ++ peer)
{
- if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
- peer -> outgoingBandwidthThrottleEpoch == timeCurrent)
- continue;
+ if (dataTotal < bandwidth)
+ throttle = ENET_PEER_PACKET_THROTTLE_SCALE;
+ else
+ throttle = (bandwidth * ENET_PEER_PACKET_THROTTLE_SCALE) / dataTotal;
- peer -> packetThrottleLimit = throttle;
+ for (peer = host -> peers;
+ peer < & host -> peers [host -> peerCount];
+ ++ peer)
+ {
+ if ((peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER) ||
+ peer -> outgoingBandwidthThrottleEpoch == timeCurrent)
+ continue;
+
+ peer -> packetThrottleLimit = throttle;
+
+ if (peer -> packetThrottle > peer -> packetThrottleLimit)
+ peer -> packetThrottle = peer -> packetThrottleLimit;
- if (peer -> packetThrottle > peer -> packetThrottleLimit)
- peer -> packetThrottle = peer -> packetThrottleLimit;
+ peer -> incomingDataTotal = 0;
+ peer -> outgoingDataTotal = 0;
+ }
}
-
+
if (host -> recalculateBandwidthLimits)
{
host -> recalculateBandwidthLimits = 0;
@@ -484,14 +492,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
}
}
-
- for (peer = host -> peers;
- peer < & host -> peers [host -> peerCount];
- ++ peer)
- {
- peer -> incomingDataTotal = 0;
- peer -> outgoingDataTotal = 0;
- }
}
/** @} */