From 6babfe64c6789ccd1e9a708c791305f3f50d2fe5 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 9 Jun 2016 18:43:16 +0200 Subject: [PATCH] Fixed bandwidth sometimes being wrongly measured. --- lib/socket.cpp | 6 ++++++ lib/socket.h | 1 + src/controller/controller_statistics.cpp | 14 ++------------ src/controller/controller_statistics.h | 4 ---- src/output/output.cpp | 1 + 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/socket.cpp b/lib/socket.cpp index bf7f92e4..3196e589 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -209,6 +209,12 @@ Socket::Connection::Connection() { Blocking = false; } //Socket::Connection basic constructor + +void Socket::Connection::resetCounter(){ + up = 0; + down = 0; +} + /// Internally used call to make an file descriptor blocking or not. void setFDBlocking(int FD, bool blocking) { int flags = fcntl(FD, F_GETFL, 0); diff --git a/lib/socket.h b/lib/socket.h index 633d6ab5..0d74cd95 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -90,6 +90,7 @@ namespace Socket { unsigned int connTime();///< Returns the time this socket has been connected. uint64_t dataUp(); ///< Returns total amount of bytes sent. uint64_t dataDown(); ///< Returns total amount of bytes received. + void resetCounter(); ///< Resets the up/down bytes counter to zero. std::string getStats(std::string C); ///< Returns a std::string of stats, ended by a newline. friend class Server; bool Error; ///< Set to true if a socket error happened. diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index aee7925a..74175a12 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -640,11 +640,6 @@ long long Controller::statSession::getBpsUp(unsigned long long t){ } } -Controller::statStorage::statStorage(){ - removeDown = 0; - removeUp = 0; -} - /// Returns true if there is data available for timestamp t. bool Controller::statStorage::hasDataFor(unsigned long long t) { if (!log.size()){return false;} @@ -674,13 +669,8 @@ void Controller::statStorage::update(IPC::statExchange & data) { statLog tmp; tmp.time = data.time(); tmp.lastSecond = data.lastSecond(); - tmp.down = data.down() - removeDown; - tmp.up = data.up() - removeUp; - if (!log.size() && tmp.down + tmp.up > COUNTABLE_BYTES){ - //substract the start values if they are too high - this is a resumed connection of some sort - removeDown = tmp.down; - removeUp = tmp.up; - } + tmp.down = data.down(); + tmp.up = data.up(); log[data.now()] = tmp; //wipe data older than approx. STAT_CUTOFF seconds /// \todo Remove least interesting data first. diff --git a/src/controller/controller_statistics.h b/src/controller/controller_statistics.h index c38d07d7..a9dddda5 100644 --- a/src/controller/controller_statistics.h +++ b/src/controller/controller_statistics.h @@ -62,11 +62,7 @@ namespace Controller { class statStorage { - private: - long long removeUp; - long long removeDown; public: - statStorage(); void update(IPC::statExchange & data); bool hasDataFor(unsigned long long); statLog & getDataFor(unsigned long long); diff --git a/src/output/output.cpp b/src/output/output.cpp index 55cf3c76..4691e6a5 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -241,6 +241,7 @@ namespace Mist { } if (statsPage.getData()){ statsPage.finish(); + myConn.resetCounter(); } statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true); if (nProxy.userClient.getData()){