summaryrefslogtreecommitdiff
path: root/src/StreamFileAllocationEntry.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/StreamFileAllocationEntry.cc')
-rw-r--r--src/StreamFileAllocationEntry.cc38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/StreamFileAllocationEntry.cc b/src/StreamFileAllocationEntry.cc
index dfe1f679..e02bbc48 100644
--- a/src/StreamFileAllocationEntry.cc
+++ b/src/StreamFileAllocationEntry.cc
@@ -49,35 +49,40 @@
namespace aria2 {
-StreamFileAllocationEntry::StreamFileAllocationEntry
-(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand):
- FileAllocationEntry(requestGroup, std::move(nextCommand))
-{}
+StreamFileAllocationEntry::StreamFileAllocationEntry(
+ RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand)
+ : FileAllocationEntry(requestGroup, std::move(nextCommand))
+{
+}
StreamFileAllocationEntry::~StreamFileAllocationEntry() {}
-void StreamFileAllocationEntry::prepareForNextAction
-(std::vector<std::unique_ptr<Command>>& commands,
- DownloadEngine* e)
+void StreamFileAllocationEntry::prepareForNextAction(
+ std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
{
+ auto& option = getRequestGroup()->getOption();
+
// For DownloadContext::resetDownloadStartTime(), see also
// RequestGroup::createInitialCommand()
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
- if(getRequestGroup()->getOption()->getAsBool(PREF_ENABLE_MMAP)) {
+ 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()) {
+ if (getNextCommand()) {
// Reset download start time of PeerStat because it is started
// before file allocation begins.
const std::shared_ptr<DownloadContext>& dctx =
- getRequestGroup()->getDownloadContext();
- const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
- dctx->getFileEntries();
- for(auto & f : fileEntries) {
+ getRequestGroup()->getDownloadContext();
+ const std::vector<std::shared_ptr<FileEntry>>& fileEntries =
+ dctx->getFileEntries();
+ for (auto& f : fileEntries) {
const auto& reqs = f->getInFlightRequests();
- for(auto & req : reqs) {
+ for (auto& req : reqs) {
const std::shared_ptr<PeerStat>& peerStat = req->getPeerStat();
- if(peerStat) {
+ if (peerStat) {
peerStat->downloadStart();
}
}
@@ -88,7 +93,8 @@ void StreamFileAllocationEntry::prepareForNextAction
commands.push_back(popNextCommand());
// try remaining uris
getRequestGroup()->createNextCommandWithAdj(commands, e, -1);
- } else {
+ }
+ else {
getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
}
}