summaryrefslogtreecommitdiff
path: root/src/net/connection.cpp
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2008-11-19 13:36:50 +0000
committerDavid Athay <ko2fan@gmail.com>2008-11-19 15:02:10 +0000
commit8481413ea17177945d3d280b1518eb6f1f25cd5d (patch)
tree77ed689d7587a6d06c07dd81c3ca0d5c49b3284d /src/net/connection.cpp
parent751cc20a3be820724ca575aab32c2bb424f89a5b (diff)
downloadmanaserv-8481413ea17177945d3d280b1518eb6f1f25cd5d.tar.gz
manaserv-8481413ea17177945d3d280b1518eb6f1f25cd5d.tar.bz2
manaserv-8481413ea17177945d3d280b1518eb6f1f25cd5d.tar.xz
manaserv-8481413ea17177945d3d280b1518eb6f1f25cd5d.zip
Added bandwidth monitoring
Diffstat (limited to 'src/net/connection.cpp')
-rw-r--r--src/net/connection.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/net/connection.cpp b/src/net/connection.cpp
index 4749c888..c99ee909 100644
--- a/src/net/connection.cpp
+++ b/src/net/connection.cpp
@@ -20,6 +20,7 @@
*/
#include "net/connection.hpp"
+#include "net/bandwidth.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
#include "utils/logger.h"
@@ -28,6 +29,7 @@ Connection::Connection():
mRemote(0),
mLocal(0)
{
+ mBandwidth = new BandwidthMonitor;
}
bool Connection::start(std::string const &address, int port)
@@ -66,9 +68,11 @@ void Connection::stop()
enet_peer_reset(mRemote);
if (mLocal)
enet_host_destroy(mLocal);
+ delete mBandwidth;
mRemote = 0;
mLocal = 0;
+ mBandwidth = 0;
}
bool Connection::isConnected() const
@@ -83,6 +87,8 @@ void Connection::send(MessageOut const &msg, bool reliable, unsigned channel)
return;
}
+ mBandwidth->increaseOutput(msg.getLength());
+
ENetPacket *packet;
packet = enet_packet_create(msg.getData(),
msg.getLength(),
@@ -107,6 +113,7 @@ void Connection::process()
{
MessageIn msg((char *)event.packet->data,
event.packet->dataLength);
+ mBandwidth->increaseInput(event.packet->dataLength);
processMessage(msg);
}
else
@@ -122,3 +129,13 @@ void Connection::process()
}
}
}
+
+int Connection::totalOut()
+{
+ return mBandwidth->totalOut();
+}
+
+int Connection::totalIn()
+{
+ return mBandwidth->totalIn();
+}