From 65e0ffe6caa5f3ad9b4ccf49045f9e7ed144ee07 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 21 Sep 2006 06:56:54 +0000 Subject: 2006-09-21 Tatsuhiro Tsujikawa * src/AbstractCommand.cc (execute): Check whether the download has finished before checking socket status. Return true if peerStat->getStatus() == REQUEST_IDLE. Do not exit even if no segment is available. * src/prefs.h (PREF_STARTUP_IDLE_TIME): New definition. * src/PeerInteractionCommand.cc (executeInternal): Removed max speed limit. Because it performs bad. (receiveMessages): Added max speed limit. This was better than above, but still a little bit to be desired. Sometimes the download speed became much faster than I specified. * src/SpeedCalc.h (start): New variable. (accumulatedLength): New variable. (getAvgSpeed): New function. * src/SpeedCalc.cc (reset): Added start, accumulatedLength. (update): Added calculation of an average speed. (getAvgSpeed): New function. * src/DownloadCommand.h (sw): Removed. * src/main.cc (main): Added PREF_STARTUP_IDLE_TIME. * src/PeerStat.h (STATUS): Added REQUEST_IDLE. (getMaxSpeed): Renamed as getMaxDownloadSpeed(). (getAvgDownloadSpeed): New function (requestIdle): New function. * src/SegmentMan.h (SegmentEntryHandle): New type definition. (SegmentEntries): Now holds SegmentEntryHandle. (findSlowerSegmentEntry): New funtion. * src/SegmentMan.cc (save): Updated according to the changes in SegmentEntries. (read): Updated according to the changes in SegmentEntries. (FindSegmentEntryByIndex): Updated according to the changes in SegmentEntries. (FindSegmentEntryByCuid): Updated according to the changes in SegmentEntries. (checkoutSegment): Updated according to the changes in SegmentEntries. (onNullBitfield): Updated according to the changes in SegmentEntries. Renamed uitr as itr. (findSlowerSegmentEntry): New function. (getSegment): Updated according to the changes in SegmentEntries. Added the feature that cancels the segment with slow server and fast one takes it over. (cancelSegment): Updated according to the changes in SegmentEntries. (getDownloadLength): Updated according to the changes in SegmentEntries. (init): Assigned 0 to bitfield after deleting it. * src/DownloadCommand.cc (STARTUP_IDLE_TIME): Removed. (executeInternal): Use PREF_STARTUP_IDLE_TIME. --- src/SpeedCalc.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/SpeedCalc.cc') diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc index 10750cc2..d61ddeb3 100644 --- a/src/SpeedCalc.cc +++ b/src/SpeedCalc.cc @@ -39,6 +39,8 @@ void SpeedCalc::reset() { sw = 0; maxSpeed = 0; prevSpeed = 0; + start.reset(); + accumulatedLength = 0; } int SpeedCalc::calculateSpeed() { @@ -65,6 +67,7 @@ public: }; void SpeedCalc::update(int bytes) { + accumulatedLength += bytes; for_each(&lengthArray[0], &lengthArray[2], Plus(bytes)); if(isIntervalOver()) { changeSw(); @@ -80,3 +83,13 @@ void SpeedCalc::changeSw() { cpArray[sw].reset(); sw ^= 0x01; } + +int SpeedCalc::getAvgSpeed() const { + int milliElapsed = start.differenceInMillis(); + if(milliElapsed) { + int speed = accumulatedLength*1000/milliElapsed; + return speed; + } else { + return 0; + } +} -- cgit