diff options
Diffstat (limited to 'src/net/connection.cpp')
-rw-r--r-- | src/net/connection.cpp | 17 |
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(); +} |