aboutsummaryrefslogtreecommitdiffhomepage
path: root/host.c
diff options
context:
space:
mode:
authorlsalzman <[email protected]>2013-05-08 10:46:17 +0300
committerlsalzman <[email protected]>2013-05-08 10:46:17 +0300
commit30d859f9a42900e0717166caefe7986f0e0a75c3 (patch)
tree678723bb6d21c6d2c540169602b60c8e8e7f7ca1 /host.c
parent27d41dd2ae1d9b43cbf3c282241ef22ddf87242d (diff)
downloadenet-30d859f9a42900e0717166caefe7986f0e0a75c3.tar.gz
enet-30d859f9a42900e0717166caefe7986f0e0a75c3.zip
avoid some looping in enet_host_bandwidth_throttle
Diffstat (limited to 'host.c')
-rw-r--r--host.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/host.c b/host.c
index 92fe1b6..a95fed6 100644
--- a/host.c
+++ b/host.c
@@ -334,13 +334,15 @@ enet_host_bandwidth_throttle (ENetHost * host)
bandwidth,
throttle = 0,
bandwidthLimit = 0;
- int needsAdjustment;
+ int needsAdjustment = 0;
ENetPeer * peer;
ENetProtocol command;
if (elapsedTime < ENET_HOST_BANDWIDTH_THROTTLE_INTERVAL)
return;
+ host -> bandwidthThrottleEpoch = timeCurrent;
+
for (peer = host -> peers;
peer < & host -> peers [host -> peerCount];
++ peer)
@@ -348,6 +350,9 @@ enet_host_bandwidth_throttle (ENetHost * host)
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
continue;
+ if (peer -> incomingBandwidth != 0)
+ needsAdjustment = 1;
+
++ peersTotal;
dataTotal += peer -> outgoingDataTotal;
}
@@ -356,13 +361,17 @@ enet_host_bandwidth_throttle (ENetHost * host)
return;
peersRemaining = peersTotal;
- needsAdjustment = 1;
if (host -> outgoingBandwidth == 0)
bandwidth = ~0;
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;
@@ -398,7 +407,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
peer -> outgoingBandwidthThrottleEpoch = timeCurrent;
-
needsAdjustment = 1;
-- peersRemaining;
bandwidth -= peerBandwidth;
@@ -477,8 +485,6 @@ enet_host_bandwidth_throttle (ENetHost * host)
}
}
- host -> bandwidthThrottleEpoch = timeCurrent;
-
for (peer = host -> peers;
peer < & host -> peers [host -> peerCount];
++ peer)