/* */ #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" #include "LogFactory.h" namespace aria2 { StreamFileAllocationEntry::StreamFileAllocationEntry( RequestGroup* requestGroup, std::unique_ptr nextCommand) : FileAllocationEntry(requestGroup, std::move(nextCommand)) { } StreamFileAllocationEntry::~StreamFileAllocationEntry() = default; void StreamFileAllocationEntry::prepareForNextAction( std::vector>& commands, DownloadEngine* e) { auto rg = getRequestGroup(); auto& dctx = rg->getDownloadContext(); auto& ps = rg->getPieceStorage(); auto diskAdaptor = ps->getDiskAdaptor(); auto& option = rg->getOption(); // For DownloadContext::resetDownloadStartTime(), see also // RequestGroup::createInitialCommand() dctx->resetDownloadStartTime(); if (option->getAsBool(PREF_ENABLE_MMAP) && option->get(PREF_FILE_ALLOCATION) != V_NONE && diskAdaptor->size() <= option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) { diskAdaptor->enableMmap(); } if (getNextCommand()) { // Reset download start time of PeerStat because it is started // before file allocation begins. const auto& fileEntries = dctx->getFileEntries(); for (auto& f : fileEntries) { const auto& reqs = f->getInFlightRequests(); for (auto& req : reqs) { const auto& 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 rg->createNextCommandWithAdj(commands, e, -1); } else { rg->createNextCommandWithAdj(commands, e, 0); } if (option->getAsInt(PREF_AUTO_SAVE_INTERVAL) != 0 && !rg->allDownloadFinished()) { try { rg->saveControlFile(); } catch (RecoverableException& e) { A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e); } } } } // namespace aria2