Fix counter overflow at 4GB

Add GB range to byte counters
pull/1/head
Timothy Pearson 10 years ago
parent 7f6ac0ab64
commit c903aeab54

@ -1,4 +1,5 @@
/*************************************************************************** /***************************************************************************
* (c) 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net> *
* Copyright (C) 2004-2005 by Hugo Parente Lima * * Copyright (C) 2004-2005 by Hugo Parente Lima *
* hugo_pl@users.sourceforge.net * * hugo_pl@users.sourceforge.net *
* * * *
@ -109,13 +110,13 @@ public:
inline Mode viewMode() const; inline Mode viewMode() const;
/// Total of bytes receiveds /// Total of bytes receiveds
inline unsigned int totalBytesRx() const; inline unsigned long totalBytesRx() const;
/// Total of bytes transmitted /// Total of bytes transmitted
inline unsigned int totalBytesTx() const; inline unsigned long totalBytesTx() const;
/// Total of packets receiveds /// Total of packets receiveds
inline unsigned int totalPktRx() const; inline unsigned long totalPktRx() const;
/// Total of packets transmitted /// Total of packets transmitted
inline unsigned int totalPktTx() const; inline unsigned long totalPktTx() const;
/// RX Speed in bytes per second /// RX Speed in bytes per second
inline double byteSpeedRx() const; inline double byteSpeedRx() const;
/// TX Speed in bytes per second /// TX Speed in bytes per second
@ -224,19 +225,19 @@ KNetStatsView::Mode KNetStatsView::viewMode() const {
return mOptions.mViewMode; return mOptions.mViewMode;
} }
unsigned int KNetStatsView::totalBytesRx() const { unsigned long KNetStatsView::totalBytesRx() const {
return mTotalBytesRx; return mTotalBytesRx;
} }
unsigned int KNetStatsView::totalBytesTx() const { unsigned long KNetStatsView::totalBytesTx() const {
return mTotalBytesTx; return mTotalBytesTx;
} }
unsigned int KNetStatsView::totalPktRx() const { unsigned long KNetStatsView::totalPktRx() const {
return mTotalPktRx; return mTotalPktRx;
} }
unsigned int KNetStatsView::totalPktTx() const { unsigned long KNetStatsView::totalPktTx() const {
return mTotalPktTx; return mTotalPktTx;
} }

@ -1,4 +1,5 @@
/*************************************************************************** /***************************************************************************
* (c) 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net> *
* Copyright (C) 2004 by Hugo Parente Lima * * Copyright (C) 2004 by Hugo Parente Lima *
* hugo_pl@users.sourceforge.net * * hugo_pl@users.sourceforge.net *
* * * *
@ -41,7 +42,7 @@ public:
* \param ksufix Sufix for kilobytes * \param ksufix Sufix for kilobytes
* \param msufix Sufix for megabytes * \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(); void show();
private: private:
@ -55,13 +56,19 @@ private slots:
void update(); 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_KB = 1024.0;
const double ONE_MB = ONE_KB*ONE_KB; const double ONE_MB = ONE_KB*ONE_KB;
if ( num >= ONE_MB ) // MB const double ONE_GB = ONE_KB*ONE_KB*ONE_KB;
return TQString::number( num/(ONE_MB), 'f', 1 ) + msufix; if ( num >= ONE_GB ) { // GB
else // Kb return TQString::number( num/(ONE_GB), 'f', 1 ) + gsuffix;
return TQString::number( num/ONE_KB, 'f', 1 ) + ksufix; }
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 #endif

Loading…
Cancel
Save