summaryrefslogtreecommitdiff
path: root/src/TimeA2.cc
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/TimeA2.cc
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/TimeA2.cc')
-rw-r--r--src/TimeA2.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/TimeA2.cc b/src/TimeA2.cc
index 7c56ed65..421760cd 100644
--- a/src/TimeA2.cc
+++ b/src/TimeA2.cc
@@ -79,6 +79,11 @@ long long int Time::differenceInMillis() const {
return Util::difftv(getCurrentTime(), tv)/1000;
}
+int64_t Time::differenceInMillis(const struct timeval& now) const
+{
+ return Util::difftv(now, tv)/1000;
+}
+
void Time::setTimeInSec(int sec) {
tv.tv_sec = sec;
tv.tv_usec = 0;