Fix counter overflow at 4GB

Add GB range to byte counters
(cherry picked from commit c903aeab54)
r14.0.x
Timothy Pearson 10 years ago committed by Slávek Banko
parent 7f6ac0ab64
commit b8063fc2f4

@ -1,5 +1,6 @@
/***************************************************************************
* Copyright (C) 2004-2005 by Hugo Parente Lima *
* (c) 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net> *
* Copyright (C) 2004-2005 by Hugo Parente Lima *
* hugo_pl@users.sourceforge.net *
* *
* 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;
}

@ -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"

@ -1,4 +1,5 @@
/***************************************************************************
* (c) 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net> *
* Copyright (C) 2004 by Hugo Parente Lima *
* hugo_pl@users.sourceforge.net *
* *
@ -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

Loading…
Cancel
Save