/* */ #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, std::unique_ptr nextCommand) : FileAllocationEntry(requestGroup, std::move(nextCommand)) { } StreamFileAllocationEntry::~StreamFileAllocationEntry() {} void StreamFileAllocationEntry::prepareForNextAction( std::vector>& commands, DownloadEngine* e) { auto& option = getRequestGroup()->getOption(); // For DownloadContext::resetDownloadStartTime(), see also // RequestGroup::createInitialCommand() getRequestGroup()->getDownloadContext()->resetDownloadStartTime(); if (option->getAsBool(PREF_ENABLE_MMAP) && option->get(PREF_FILE_ALLOCATION) != V_NONE && getRequestGroup()->getPieceStorage()->getDiskAdaptor()->size() <= option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) { getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap(); } if (getNextCommand()) { // Reset download start time of PeerStat because it is started // before file allocation begins. const std::shared_ptr& dctx = getRequestGroup()->getDownloadContext(); const std::vector>& fileEntries = dctx->getFileEntries(); for (auto& f : fileEntries) { const auto& reqs = f->getInFlightRequests(); for (auto& req : reqs) { const std::shared_ptr& peerStat = req->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