From 24d258cf66a18ebff73dfc2baea10fc85b7e3fbf Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 4 Jul 2009 15:26:00 +0000 Subject: 2009-07-05 Tatsuhiro Tsujikawa Call RequestGroup::createNextCommandWithAdj() from BtFileAllocationEntry if at least one FileEntry has URI. The static function hasAssociatedUri in RequestGroup.cc is renamed as isUriSuppliedForRequsetFileEntry() and placed in FileEntry.h. * src/BtFileAllocationEntry.cc * src/FileEntry.h * src/RequestGroup.cc --- src/BtFileAllocationEntry.cc | 6 +++++- src/FileEntry.h | 12 ++++++++++++ src/RequestGroup.cc | 17 +++-------------- 3 files changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc index 861a634e..e730e92b 100644 --- a/src/BtFileAllocationEntry.cc +++ b/src/BtFileAllocationEntry.cc @@ -55,7 +55,11 @@ void BtFileAllocationEntry::prepareForNextAction(std::deque& commands, BtSetup().setup(commands, _requestGroup, e, _requestGroup->getOption().get()); if(!_requestGroup->downloadFinished()) { _requestGroup->getDownloadContext()->resetDownloadStartTime(); - _requestGroup->createNextCommandWithAdj(commands, e, 0); + const std::vector >& fileEntries = + _requestGroup->getDownloadContext()->getFileEntries(); + if(isUriSuppliedForRequsetFileEntry(fileEntries.begin(), fileEntries.end())) { + _requestGroup->createNextCommandWithAdj(commands, e, 0); + } } } diff --git a/src/FileEntry.h b/src/FileEntry.h index a52b2f02..74716141 100644 --- a/src/FileEntry.h +++ b/src/FileEntry.h @@ -265,6 +265,18 @@ size_t countRequestedFileEntry(InputIterator first, InputIterator last) return count; } +// Returns true if at least one requested FileEntry has URIs. +template +bool isUriSuppliedForRequsetFileEntry(InputIterator first, InputIterator last) +{ + for(; first != last; ++first) { + if((*first)->isRequested() && !(*first)->getRemainingUris().empty()) { + return true; + } + } + return false; +} + // Writes first filename to given o. If memory is true, the output is // "[MEMORY]" plus the basename of the first filename. If there is no // FileEntry, writes "n/a" to o. If more than 1 FileEntry are in the diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index e5829b19..cbf24b68 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -398,17 +398,6 @@ void RequestGroup::processCheckIntegrityEntry(std::deque& commands, } } -template -static bool hasAssociatedUri(InputIterator first, InputIterator last) -{ - for(; first != last; ++first) { - if((*first)->isRequested() && !(*first)->getRemainingUris().empty()) { - return true; - } - } - return false; -} - void RequestGroup::initPieceStorage() { if(_downloadContext->knowsTotalLength()) { @@ -418,8 +407,9 @@ void RequestGroup::initPieceStorage() // Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent integrated // downloads. Currently multi-file integrated download is not supported. if(_downloadContext->hasAttribute(bittorrent::BITTORRENT) && - hasAssociatedUri(_downloadContext->getFileEntries().begin(), - _downloadContext->getFileEntries().end())) { + isUriSuppliedForRequsetFileEntry + (_downloadContext->getFileEntries().begin(), + _downloadContext->getFileEntries().end())) { _logger->debug("Using LongestSequencePieceSelector"); ps->setPieceSelector (SharedHandle(new LongestSequencePieceSelector())); @@ -635,7 +625,6 @@ void RequestGroup::createNextCommand(std::deque& commands, for(; numCommand--; ) { Command* command = new CreateRequestCommand(e->newCUID(), this, e); - _logger->debug("filePath=%s", _downloadContext->getFileEntries().front()->getPath().c_str()); commands.push_back(command); } if(!commands.empty()) { -- cgit