mirror of https://github.com/aria2/aria2
Refactor
parent
924e115e3e
commit
9eff8100ef
|
@ -60,30 +60,30 @@ BtFileAllocationEntry::~BtFileAllocationEntry() = default;
|
||||||
void BtFileAllocationEntry::prepareForNextAction(
|
void BtFileAllocationEntry::prepareForNextAction(
|
||||||
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
auto& option = getRequestGroup()->getOption();
|
auto rg = getRequestGroup();
|
||||||
|
auto& dctx = rg->getDownloadContext();
|
||||||
|
auto& ps = rg->getPieceStorage();
|
||||||
|
auto diskAdaptor = ps->getDiskAdaptor();
|
||||||
|
auto& option = rg->getOption();
|
||||||
|
|
||||||
BtSetup().setup(commands, getRequestGroup(), e, option.get());
|
BtSetup().setup(commands, rg, e, option.get());
|
||||||
if (option->getAsBool(PREF_ENABLE_MMAP) &&
|
if (option->getAsBool(PREF_ENABLE_MMAP) &&
|
||||||
option->get(PREF_FILE_ALLOCATION) != V_NONE &&
|
option->get(PREF_FILE_ALLOCATION) != V_NONE &&
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->size() <=
|
diskAdaptor->size() <= option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
|
||||||
option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
|
diskAdaptor->enableMmap();
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap();
|
|
||||||
}
|
}
|
||||||
if (!getRequestGroup()->downloadFinished()) {
|
if (!rg->downloadFinished()) {
|
||||||
// For DownloadContext::resetDownloadStartTime(), see also
|
// For DownloadContext::resetDownloadStartTime(), see also
|
||||||
// RequestGroup::createInitialCommand()
|
// RequestGroup::createInitialCommand()
|
||||||
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
|
dctx->resetDownloadStartTime();
|
||||||
const std::vector<std::shared_ptr<FileEntry>>& fileEntries =
|
const auto& fileEntries = dctx->getFileEntries();
|
||||||
getRequestGroup()->getDownloadContext()->getFileEntries();
|
|
||||||
if (isUriSuppliedForRequsetFileEntry(std::begin(fileEntries),
|
if (isUriSuppliedForRequsetFileEntry(std::begin(fileEntries),
|
||||||
std::end(fileEntries))) {
|
std::end(fileEntries))) {
|
||||||
getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
|
rg->createNextCommandWithAdj(commands, e, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
const std::shared_ptr<DiskAdaptor>& diskAdaptor =
|
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor();
|
|
||||||
if (!diskAdaptor->isReadOnlyEnabled()) {
|
if (!diskAdaptor->isReadOnlyEnabled()) {
|
||||||
// On Windows, if aria2 opens files with GENERIC_WRITE access
|
// On Windows, if aria2 opens files with GENERIC_WRITE access
|
||||||
// right, some programs cannot open them aria2 is seeding. To
|
// right, some programs cannot open them aria2 is seeding. To
|
||||||
|
@ -96,7 +96,7 @@ void BtFileAllocationEntry::prepareForNextAction(
|
||||||
diskAdaptor->openFile();
|
diskAdaptor->openFile();
|
||||||
}
|
}
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
getRequestGroup()->enableSeedOnly();
|
rg->enableSeedOnly();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,28 +60,28 @@ StreamFileAllocationEntry::~StreamFileAllocationEntry() = default;
|
||||||
void StreamFileAllocationEntry::prepareForNextAction(
|
void StreamFileAllocationEntry::prepareForNextAction(
|
||||||
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||||
{
|
{
|
||||||
auto& option = getRequestGroup()->getOption();
|
auto rg = getRequestGroup();
|
||||||
|
auto& dctx = rg->getDownloadContext();
|
||||||
|
auto& ps = rg->getPieceStorage();
|
||||||
|
auto diskAdaptor = ps->getDiskAdaptor();
|
||||||
|
auto& option = rg->getOption();
|
||||||
|
|
||||||
// For DownloadContext::resetDownloadStartTime(), see also
|
// For DownloadContext::resetDownloadStartTime(), see also
|
||||||
// RequestGroup::createInitialCommand()
|
// RequestGroup::createInitialCommand()
|
||||||
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
|
dctx->resetDownloadStartTime();
|
||||||
if (option->getAsBool(PREF_ENABLE_MMAP) &&
|
if (option->getAsBool(PREF_ENABLE_MMAP) &&
|
||||||
option->get(PREF_FILE_ALLOCATION) != V_NONE &&
|
option->get(PREF_FILE_ALLOCATION) != V_NONE &&
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->size() <=
|
diskAdaptor->size() <= option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
|
||||||
option->getAsLLInt(PREF_MAX_MMAP_LIMIT)) {
|
diskAdaptor->enableMmap();
|
||||||
getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableMmap();
|
|
||||||
}
|
}
|
||||||
if (getNextCommand()) {
|
if (getNextCommand()) {
|
||||||
// Reset download start time of PeerStat because it is started
|
// Reset download start time of PeerStat because it is started
|
||||||
// before file allocation begins.
|
// before file allocation begins.
|
||||||
const std::shared_ptr<DownloadContext>& dctx =
|
const auto& fileEntries = dctx->getFileEntries();
|
||||||
getRequestGroup()->getDownloadContext();
|
|
||||||
const std::vector<std::shared_ptr<FileEntry>>& fileEntries =
|
|
||||||
dctx->getFileEntries();
|
|
||||||
for (auto& f : fileEntries) {
|
for (auto& f : fileEntries) {
|
||||||
const auto& reqs = f->getInFlightRequests();
|
const auto& reqs = f->getInFlightRequests();
|
||||||
for (auto& req : reqs) {
|
for (auto& req : reqs) {
|
||||||
const std::shared_ptr<PeerStat>& peerStat = req->getPeerStat();
|
const auto& peerStat = req->getPeerStat();
|
||||||
if (peerStat) {
|
if (peerStat) {
|
||||||
peerStat->downloadStart();
|
peerStat->downloadStart();
|
||||||
}
|
}
|
||||||
|
@ -92,10 +92,10 @@ void StreamFileAllocationEntry::prepareForNextAction(
|
||||||
e->setNoWait(true);
|
e->setNoWait(true);
|
||||||
commands.push_back(popNextCommand());
|
commands.push_back(popNextCommand());
|
||||||
// try remaining uris
|
// try remaining uris
|
||||||
getRequestGroup()->createNextCommandWithAdj(commands, e, -1);
|
rg->createNextCommandWithAdj(commands, e, -1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
|
rg->createNextCommandWithAdj(commands, e, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue