diff options
author | Timothy Pearson <[email protected]> | 2015-03-12 12:00:08 -0500 |
---|---|---|
committer | Slávek Banko <[email protected]> | 2015-03-12 18:11:32 +0100 |
commit | b8063fc2f49dc62e661114e2eddb7b0c7b4293e1 (patch) | |
tree | 1a7473d58e7d977d41af0ff6f57a401dae1343c8 | |
parent | 7f6ac0ab640e0690d103cca2cd62bc8d99bce645 (diff) | |
download | knetstats-b8063fc2f49dc62e661114e2eddb7b0c7b4293e1.tar.gz knetstats-b8063fc2f49dc62e661114e2eddb7b0c7b4293e1.zip |
Fix counter overflow at 4GB
Add GB range to byte counters
(cherry picked from commit c903aeab541d6a6d0c41f78d06917523c84c167d)
-rw-r--r-- | src/src/knetstatsview.h | 21 | ||||
-rw-r--r-- | src/src/statistics.cpp | 2 | ||||
-rw-r--r-- | src/src/statistics.h | 21 |
3 files changed, 26 insertions, 18 deletions
diff --git a/src/src/knetstatsview.h b/src/src/knetstatsview.h index a0dab81..e8cc0b8 100644 --- a/src/src/knetstatsview.h +++ b/src/src/knetstatsview.h @@ -1,5 +1,6 @@ /*************************************************************************** -* Copyright (C) 2004-2005 by Hugo Parente Lima * +* (c) 2015 Timothy Pearson <[email protected]> * +* Copyright (C) 2004-2005 by Hugo Parente Lima * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +16,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KNETSTATSVIEW_H @@ -109,13 +110,13 @@ public: inline Mode viewMode() const; /// Total of bytes receiveds - inline unsigned int totalBytesRx() const; + inline unsigned long totalBytesRx() const; /// Total of bytes transmitted - inline unsigned int totalBytesTx() const; + inline unsigned long totalBytesTx() const; /// Total of packets receiveds - inline unsigned int totalPktRx() const; + inline unsigned long totalPktRx() const; /// Total of packets transmitted - inline unsigned int totalPktTx() const; + inline unsigned long totalPktTx() const; /// RX Speed in bytes per second inline double byteSpeedRx() const; /// TX Speed in bytes per second @@ -224,19 +225,19 @@ KNetStatsView::Mode KNetStatsView::viewMode() const { return mOptions.mViewMode; } -unsigned int KNetStatsView::totalBytesRx() const { +unsigned long KNetStatsView::totalBytesRx() const { return mTotalBytesRx; } -unsigned int KNetStatsView::totalBytesTx() const { +unsigned long KNetStatsView::totalBytesTx() const { return mTotalBytesTx; } -unsigned int KNetStatsView::totalPktRx() const { +unsigned long KNetStatsView::totalPktRx() const { return mTotalPktRx; } -unsigned int KNetStatsView::totalPktTx() const { +unsigned long KNetStatsView::totalPktTx() const { return mTotalPktTx; } diff --git a/src/src/statistics.cpp b/src/src/statistics.cpp index 7292334..6097be1 100644 --- a/src/src/statistics.cpp +++ b/src/src/statistics.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "statistics.h" #include "chart.h" diff --git a/src/src/statistics.h b/src/src/statistics.h index f837768..637b965 100644 --- a/src/src/statistics.h +++ b/src/src/statistics.h @@ -1,4 +1,5 @@ /*************************************************************************** +* (c) 2015 Timothy Pearson <[email protected]> * * Copyright (C) 2004 by Hugo Parente Lima * * * @@ -15,7 +16,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * -* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef STATISTICS_H #define STATISTICS_H @@ -41,7 +42,7 @@ public: * \param ksufix Sufix for kilobytes * \param msufix Sufix for megabytes */ - static inline TQString byteFormat( double num, const char* ksufix = " KB", const char* msufix = " MB"); + static inline TQString byteFormat( double num, const char* ksuffix = " KB", const char* msuffix = " MB", const char* gsuffix = " GB"); void show(); private: @@ -55,13 +56,19 @@ private slots: void update(); }; -TQString Statistics::byteFormat( double num, const char* ksufix, const char* msufix ) { +TQString Statistics::byteFormat( double num, const char* ksuffix, const char* msuffix, const char* gsuffix ) { const double ONE_KB = 1024.0; const double ONE_MB = ONE_KB*ONE_KB; - if ( num >= ONE_MB ) // MB - return TQString::number( num/(ONE_MB), 'f', 1 ) + msufix; - else // Kb - return TQString::number( num/ONE_KB, 'f', 1 ) + ksufix; + const double ONE_GB = ONE_KB*ONE_KB*ONE_KB; + if ( num >= ONE_GB ) { // GB + return TQString::number( num/(ONE_GB), 'f', 1 ) + gsuffix; + } + else if ( num >= ONE_MB ) { // MB + return TQString::number( num/(ONE_MB), 'f', 1 ) + msuffix; + } + else { // KB + return TQString::number( num/ONE_KB, 'f', 1 ) + ksuffix; + } } #endif |