/* */ #include "StreamFileAllocationEntry.h" #include #include "DownloadEngine.h" #include "Option.h" #include "prefs.h" #include "RequestGroup.h" #include "DownloadContext.h" #include "Command.h" #include "PeerStat.h" #include "FileEntry.h" #include "PieceStorage.h" #include "DiskAdaptor.h" namespace aria2 { StreamFileAllocationEntry::StreamFileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand): FileAllocationEntry(requestGroup, nextCommand) {} StreamFileAllocationEntry::~StreamFileAllocationEntry() {} void StreamFileAllocationEntry::prepareForNextAction (std::vector& commands, DownloadEngine* e) { // For DownloadContext::resetDownloadStartTime(), see also // RequestGroup::createInitialCommand() getRequestGroup()->getDownloadContext()->resetDownloadStartTime(); if(getRequestGroup()->getOption()->getAsBool(PREF_ENABLE_MMAP)) { getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap(); } if(getNextCommand()) { // Reset download start time of PeerStat because it is started // before file allocation begins. const SharedHandle& dctx = getRequestGroup()->getDownloadContext(); const std::vector >& fileEntries = dctx->getFileEntries(); for(std::vector >::const_iterator i = fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) { const FileEntry::InFlightRequestSet& reqs = (*i)->getInFlightRequests(); for(FileEntry::InFlightRequestSet::iterator j = reqs.begin(), eoj = reqs.end(); j != eoj; ++j) { const SharedHandle& peerStat = (*j)->getPeerStat(); if(peerStat) { peerStat->downloadStart(); } } } // give _nextCommand a chance to execute in the next execution loop. getNextCommand()->setStatus(Command::STATUS_ONESHOT_REALTIME); e->setNoWait(true); commands.push_back(popNextCommand()); // try remaining uris getRequestGroup()->createNextCommandWithAdj(commands, e, -1); } else { getRequestGroup()->createNextCommandWithAdj(commands, e, 0); } } } // namespace aria2