summaryrefslogtreecommitdiff
path: root/src/PeerStat.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-07-20 07:41:33 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-07-20 07:41:33 +0000
commitf242a1ec8fde0c47db52b0d652ad7890a153fd57 (patch)
treef16de8ede7cca2464a04f3f7c277d173cfefd471 /src/PeerStat.h
parent4947fa39b3029470b851a1cfc7f8d2152a5689e5 (diff)
2008-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Cache last calculated average download/upload speed. PeerStat::getAvgDownloadSpeed(), PeerStat::getAvgUploadSpeed() return cached value. Now SpeedCalc::changeSw() is called from SpeedCalc::calculateSpeed() * src/PeerStat.h * src/SpeedCalc.cc * src/SpeedCalc.h
Diffstat (limited to 'src/PeerStat.h')
-rw-r--r--src/PeerStat.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/PeerStat.h b/src/PeerStat.h
index ce2860f8..eb118b71 100644
--- a/src/PeerStat.h
+++ b/src/PeerStat.h
@@ -54,9 +54,13 @@ private:
SpeedCalc uploadSpeed;
Time downloadStartTime;
PeerStat::STATUS status;
+ unsigned int _avgDownloadSpeed;
+ unsigned int _avgUploadSpeed;
public:
- PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
+ PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE),
+ _avgDownloadSpeed(0),
+ _avgUploadSpeed(0) {}
~PeerStat() {}
@@ -71,6 +75,11 @@ public:
return downloadSpeed.calculateSpeed(now);
}
+ unsigned int calculateAvgDownloadSpeed() {
+ _avgDownloadSpeed = downloadSpeed.calculateAvgSpeed();
+ return _avgDownloadSpeed;
+ }
+
unsigned int calculateUploadSpeed() {
return uploadSpeed.calculateSpeed();
}
@@ -79,6 +88,11 @@ public:
return uploadSpeed.calculateSpeed(now);
}
+ unsigned int calculateAvgUploadSpeed() {
+ _avgUploadSpeed = uploadSpeed.calculateAvgSpeed();
+ return _avgUploadSpeed;
+ }
+
void updateDownloadLength(size_t bytes) {
downloadSpeed.update(bytes);
}
@@ -96,11 +110,11 @@ public:
}
unsigned int getAvgDownloadSpeed() const {
- return downloadSpeed.getAvgSpeed();
+ return _avgDownloadSpeed;
}
unsigned int getAvgUploadSpeed() const {
- return uploadSpeed.getAvgSpeed();
+ return _avgUploadSpeed;
}
void reset() {
@@ -116,6 +130,8 @@ public:
}
void downloadStop() {
+ calculateAvgDownloadSpeed();
+ calculateAvgUploadSpeed();
status = PeerStat::IDLE;
}