From 574e1b3db8c0a811c1265f36ea6c77ebf9083f33 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 6 Jan 2008 16:32:52 +0000 Subject: [PATCH] 2008-01-07 Tatsuhiro Tsujikawa Fixed the bug that SegmentMan::completeSegment() is not called even if Segment is complete when --lowest-speed-limit is enabled. BUG#1864525 * src/DownloadCommand.{h, cc} --- ChangeLog | 7 +++++++ src/DownloadCommand.cc | 26 ++++++++++++++++---------- src/DownloadCommand.h | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 24acda25..0a7fd4e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-01-07 Tatsuhiro Tsujikawa + + Fixed the bug that SegmentMan::completeSegment() is not called + even if Segment is complete when --lowest-speed-limit is enabled. + BUG#1864525 + * src/DownloadCommand.{h, cc} + 2008-01-06 Tatsuhiro Tsujikawa Fixed: hash algorithm 'sha1' is always used. diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 0f2a8b36..108d09dc 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -118,16 +118,6 @@ bool DownloadCommand::executeInternal() { //segment->writtenLength += infbufSize; peerStat->updateDownloadLength(infbufSize); } - // calculate downloading speed - if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) { - int32_t nowSpeed = peerStat->calculateDownloadSpeed(); - if(lowestDownloadSpeedLimit > 0 && nowSpeed <= lowestDownloadSpeedLimit) { - throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED, - nowSpeed, - lowestDownloadSpeedLimit, - req->getHost().c_str()); - } - } if(_requestGroup->getTotalLength() != 0 && bufSize == 0) { throw new DlRetryEx(EX_GOT_EOF); } @@ -137,14 +127,30 @@ bool DownloadCommand::executeInternal() { if(!transferDecoder.isNull()) transferDecoder->end(); logger->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, cuid); validatePieceHash(segment); + checkLowestDownloadSpeed(); // this unit is going to download another segment. return prepareForNextSegment(); } else { + checkLowestDownloadSpeed(); e->commands.push_back(this); return false; } } +void DownloadCommand::checkLowestDownloadSpeed() const +{ + // calculate downloading speed + if(peerStat->getDownloadStartTime().elapsed(startupIdleTime)) { + int32_t nowSpeed = peerStat->calculateDownloadSpeed(); + if(lowestDownloadSpeedLimit > 0 && nowSpeed <= lowestDownloadSpeedLimit) { + throw new DlAbortEx(EX_TOO_SLOW_DOWNLOAD_SPEED, + nowSpeed, + lowestDownloadSpeedLimit, + req->getHost().c_str()); + } + } +} + bool DownloadCommand::prepareForNextSegment() { if(_requestGroup->downloadFinished()) { #ifdef ENABLE_MESSAGE_DIGEST diff --git a/src/DownloadCommand.h b/src/DownloadCommand.h index 23214868..24652351 100644 --- a/src/DownloadCommand.h +++ b/src/DownloadCommand.h @@ -51,6 +51,7 @@ private: void validatePieceHash(const SegmentHandle& segment); + void checkLowestDownloadSpeed() const; protected: TransferEncodingHandle transferDecoder;