summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoreihrul <eihrul>2010-05-14 23:41:14 +0000
committereihrul <eihrul>2010-05-14 23:41:14 +0000
commit72525fbca19d4a643ae1e0547947d4d6fa32f4b4 (patch)
tree72cdff8f56a93333d4f7655e33719635dd81653c
parent94a1e8879fd98719fcac0ba28df84c5b72d52178 (diff)
downloadenet-72525fbca19d4a643ae1e0547947d4d6fa32f4b4.tar.gz
enet-72525fbca19d4a643ae1e0547947d4d6fa32f4b4.zip
added totalSentData, totalSentPackets, totalReceivedData, totalReceivedPackets
-rw-r--r--ChangeLog3
-rw-r--r--host.c5
-rw-r--r--include/enet/enet.h4
-rw-r--r--protocol.c8
4 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 8520432..1117b2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
ENet 1.2.2 (May 13, 2010):
+* added totalSentData, totalSentPackets, totalReceivedData, and
+totalReceivedPackets counters inside ENetHost for getting usage
+statistics
* added enet_host_channel_limit() for limiting the maximum number of
channels allowed by connected peers
* now uses dispatch queues for event dispatch rather than potentially
diff --git a/host.c b/host.c
index 9edceb2..67accd9 100644
--- a/host.c
+++ b/host.c
@@ -79,6 +79,11 @@ enet_host_create (const ENetAddress * address, size_t peerCount, enet_uint32 inc
host -> receivedAddress.port = 0;
host -> receivedDataLength = 0;
+ host -> totalSentData = 0;
+ host -> totalSentPackets = 0;
+ host -> totalReceivedData = 0;
+ host -> totalReceivedPackets = 0;
+
enet_list_clear (& host -> dispatchQueue);
for (currentPeer = host -> peers;
diff --git a/include/enet/enet.h b/include/enet/enet.h
index 04b416e..7d4ac33 100644
--- a/include/enet/enet.h
+++ b/include/enet/enet.h
@@ -322,6 +322,10 @@ typedef struct _ENetHost
ENetAddress receivedAddress;
enet_uint8 receivedData [ENET_PROTOCOL_MAXIMUM_MTU];
size_t receivedDataLength;
+ enet_uint32 totalSentData; /**< total data sent, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalSentPackets; /**< total UDP packets sent, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalReceivedData; /**< total data received, user should reset to 0 as needed to prevent overflow */
+ enet_uint32 totalReceivedPackets; /**< total UDP packets received, user should reset to 0 as needed to prevent overflow */
} ENetHost;
/**
diff --git a/protocol.c b/protocol.c
index 1362179..21460b1 100644
--- a/protocol.c
+++ b/protocol.c
@@ -1005,7 +1005,10 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
return 0;
host -> receivedDataLength = receivedLength;
-
+
+ host -> totalReceivedData += receivedLength;
+ host -> totalReceivedPackets ++;
+
switch (enet_protocol_handle_incoming_commands (host, event))
{
case 1:
@@ -1424,6 +1427,9 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch
if (sentLength < 0)
return -1;
+
+ host -> totalSentData += sentLength;
+ host -> totalSentPackets ++;
}
return 0;