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 *
* hugo_pl@users.sourceforge.net *
* *
@ -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;
}

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