aboutsummaryrefslogtreecommitdiffhomepage
path: root/peer.c
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2013-05-11 21:53:55 +0300
committerLee Salzman <[email protected]>2013-05-11 21:53:55 +0300
commit69b98608e5fb48160947807256ea53f5574dae37 (patch)
tree5f654f4bd2e80ef6ce82333a3425cae2672d1da7 /peer.c
parent2bb83d9813bf013b63a6b7818893dd375bd84118 (diff)
downloadenet-69b98608e5fb48160947807256ea53f5574dae37.tar.gz
enet-69b98608e5fb48160947807256ea53f5574dae37.zip
track the number of connected peers to make throttling a bit cheaper
Diffstat (limited to 'peer.c')
-rw-r--r--peer.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/peer.c b/peer.c
index a86d793..6a9641c 100644
--- a/peer.c
+++ b/peer.c
@@ -337,6 +337,30 @@ enet_peer_reset_queues (ENetPeer * peer)
peer -> channelCount = 0;
}
+void
+enet_peer_on_connect (ENetPeer * peer)
+{
+ if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
+ {
+ if (peer -> incomingBandwidth != 0)
+ ++ peer -> host -> bandwidthLimitedPeers;
+
+ ++ peer -> host -> connectedPeers;
+ }
+}
+
+void
+enet_peer_on_disconnect (ENetPeer * peer)
+{
+ if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER)
+ {
+ if (peer -> incomingBandwidth != 0)
+ -- peer -> host -> bandwidthLimitedPeers;
+
+ -- peer -> host -> connectedPeers;
+ }
+}
+
/** Forcefully disconnects a peer.
@param peer peer to forcefully disconnect
@remarks The foreign host represented by the peer is not notified of the disconnection and will timeout
@@ -345,6 +369,8 @@ enet_peer_reset_queues (ENetPeer * peer)
void
enet_peer_reset (ENetPeer * peer)
{
+ enet_peer_on_disconnect (peer);
+
peer -> outgoingPeerID = ENET_PROTOCOL_MAXIMUM_PEER_ID;
peer -> connectID = 0;
@@ -519,7 +545,11 @@ enet_peer_disconnect (ENetPeer * peer, enet_uint32 data)
enet_peer_queue_outgoing_command (peer, & command, NULL, 0, 0);
if (peer -> state == ENET_PEER_STATE_CONNECTED || peer -> state == ENET_PEER_STATE_DISCONNECT_LATER)
- peer -> state = ENET_PEER_STATE_DISCONNECTING;
+ {
+ enet_peer_notify_disconnect (peer);
+
+ peer -> state = ENET_PEER_STATE_DISCONNECTING;
+ }
else
{
enet_host_flush (peer -> host);
@@ -584,7 +614,7 @@ void
enet_peer_setup_outgoing_command (ENetPeer * peer, ENetOutgoingCommand * outgoingCommand)
{
ENetChannel * channel = & peer -> channels [outgoingCommand -> command.header.channelID];
-
+
peer -> outgoingDataTotal += enet_protocol_command_size (outgoingCommand -> command.header.command) + outgoingCommand -> fragmentLength;
if (outgoingCommand -> command.header.channelID == 0xFF)