diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-09-21 06:56:54 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2006-09-21 06:56:54 +0000 |
| commit | 65e0ffe6caa5f3ad9b4ccf49045f9e7ed144ee07 (patch) | |
| tree | 404fd056564901d0433d49dda78ae03a0f4b6475 /src/SpeedCalc.cc | |
| parent | 2fb9b5be9705560fd77b4244636bc2515e81f32c (diff) | |
2006-09-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* 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.
Diffstat (limited to 'src/SpeedCalc.cc')
| -rw-r--r-- | src/SpeedCalc.cc | 13 |
1 files changed, 13 insertions, 0 deletions
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; + } +} |
