summaryrefslogtreecommitdiff
path: root/src/SpeedCalc.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-20 14:43:34 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-06-20 14:43:34 +0000
commitd7155e8f6c1460eb5ff57164da6a05a470ca0e65 (patch)
tree37fee8fa875375c2f8bf0653ff8e8c35a632b70e /src/SpeedCalc.h
parentbe9dec85357a96e1cf77f743ccf83941a9572aad (diff)
2007-06-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Reduce the number of calls to gettimeofday to lower CPU load. * src/TimeA2.h, src/TimeA2.cc (differenceInMillis): New function. * src/SpeedCalc.h, src/SpeedCalc.cc (calculateSpeed): New function. * src/Peer.h (calculateUploadSpeed): New function. (calculateDownloadSpeed): New function. * src/DefaultPeerStorage.cc (CalculateStat): Added _now variable. In operator(), call Peer::calculateDownloadSpeed(const struct timeval&) and Peer::calculateUploadSpeed(const struct timeval&) Drop connection if no request or piece message is exchanged in a certain interval. * src/DefaultBtInteractive.h (btRuntime): New variable. (inactiveCheckPoint): New variable. (checkActiveInteraction): New function. * src/DefaultBtInteractive.cc (receiveMessages): Reset timer when request or piece message is received. (checkActiveInteraction): New function. (doInteractionProcessing): Call checkActiveInteraction. Fixed the bug that causes remote Metalink and Torrent files are not processed. * src/MultiUrlRequestInfo.cc (createNextRequestInfo): Fixed the bug.
Diffstat (limited to 'src/SpeedCalc.h')
-rw-r--r--src/SpeedCalc.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/SpeedCalc.h b/src/SpeedCalc.h
index b8d64d14..25a8b93d 100644
--- a/src/SpeedCalc.h
+++ b/src/SpeedCalc.h
@@ -40,14 +40,14 @@
class SpeedCalc {
private:
- long long int lengthArray[2];
- int sw;
+ int64_t lengthArray[2];
+ int32_t sw;
Time cpArray[2];
- int maxSpeed;
- int prevSpeed;
+ int32_t maxSpeed;
+ int32_t prevSpeed;
Time start;
- long long int accumulatedLength;
- int nextInterval;
+ int64_t accumulatedLength;
+ int32_t nextInterval;
bool isIntervalOver() const;
void changeSw();
@@ -61,13 +61,15 @@ public:
/**
* Returns download/upload speed in byte per sec
*/
- int calculateSpeed();
+ int32_t calculateSpeed();
- int getMaxSpeed() const {
+ int32_t calculateSpeed(const struct timeval& now);
+
+ int32_t getMaxSpeed() const {
return maxSpeed;
}
- int getAvgSpeed() const;
+ int32_t getAvgSpeed() const;
void update(int bytes);