mirror of https://github.com/aria2/aria2
Wrap Command object in std::unique_ptr
parent
bb5b7eeedb
commit
fa9f3fb5a3
|
@ -48,7 +48,6 @@
|
|||
#include "DownloadFailureException.h"
|
||||
#include "CreateRequestCommand.h"
|
||||
#include "InitiateConnectionCommandFactory.h"
|
||||
#include "SleepCommand.h"
|
||||
#include "StreamCheckIntegrityEntry.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "SocketCore.h"
|
||||
|
@ -133,11 +132,10 @@ void AbstractCommand::useFasterRequest
|
|||
fasterRequest->getPort()));
|
||||
// Cancel current Request object and use faster one.
|
||||
fileEntry_->removeRequest(req_);
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), fasterRequest, fileEntry_, requestGroup_, e_);
|
||||
e_->setNoWait(true);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(InitiateConnectionCommandFactory::
|
||||
createInitiateConnectionCommand
|
||||
(getCuid(), fasterRequest, fileEntry_, requestGroup_, e_));
|
||||
}
|
||||
|
||||
bool AbstractCommand::execute() {
|
||||
|
@ -301,7 +299,7 @@ bool AbstractCommand::execute() {
|
|||
}
|
||||
throw DL_RETRY_EX2(EX_TIME_OUT, error_code::TIME_OUT);
|
||||
}
|
||||
e_->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
} catch(DlAbortEx& err) {
|
||||
|
@ -390,10 +388,10 @@ void AbstractCommand::tryReserved() {
|
|||
}
|
||||
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Trying reserved/pooled request.",
|
||||
getCuid()));
|
||||
std::vector<Command*> commands;
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
requestGroup_->createNextCommand(commands, e_, 1);
|
||||
e_->setNoWait(true);
|
||||
e_->addCommand(commands);
|
||||
e_->addCommand(std::move(commands));
|
||||
}
|
||||
|
||||
bool AbstractCommand::prepareForRetry(time_t wait) {
|
||||
|
@ -415,16 +413,16 @@ bool AbstractCommand::prepareForRetry(time_t wait) {
|
|||
}
|
||||
}
|
||||
|
||||
Command* command = new CreateRequestCommand(getCuid(), requestGroup_, e_);
|
||||
auto command = make_unique<CreateRequestCommand>(getCuid(),
|
||||
requestGroup_, e_);
|
||||
if(wait == 0) {
|
||||
e_->setNoWait(true);
|
||||
e_->addCommand(command);
|
||||
} else {
|
||||
// We don't use wait so that Command can be executed by
|
||||
// DownloadEngine::setRefreshInterval(0).
|
||||
command->setStatus(Command::STATUS_INACTIVE);
|
||||
e_->addCommand(command);
|
||||
}
|
||||
e_->addCommand(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -774,11 +772,9 @@ std::string AbstractCommand::resolveHostname
|
|||
void AbstractCommand::prepareForNextAction
|
||||
(const std::shared_ptr<CheckIntegrityEntry>& checkEntry)
|
||||
{
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
requestGroup_->processCheckIntegrityEntry(*commands, checkEntry, e_);
|
||||
e_->addCommand(*commands);
|
||||
commands->clear();
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
requestGroup_->processCheckIntegrityEntry(commands, checkEntry, e_);
|
||||
e_->addCommand(std::move(commands));
|
||||
e_->setNoWait(true);
|
||||
}
|
||||
|
||||
|
@ -796,11 +792,10 @@ bool AbstractCommand::checkIfConnectionEstablished
|
|||
A2_LOG_INFO(fmt(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
getCuid(),
|
||||
connectedAddr.c_str(), connectedPort));
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), req_, fileEntry_, requestGroup_, e_);
|
||||
e_->setNoWait(true);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(InitiateConnectionCommandFactory::
|
||||
createInitiateConnectionCommand
|
||||
(getCuid(), req_, fileEntry_, requestGroup_, e_));
|
||||
return false;
|
||||
}
|
||||
e_->removeCachedIPAddress(connectedHostname, connectedPort);
|
||||
|
@ -889,4 +884,9 @@ void AbstractCommand::checkSocketRecvBuffer()
|
|||
}
|
||||
}
|
||||
|
||||
void AbstractCommand::addCommandSelf()
|
||||
{
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -222,6 +222,7 @@ public:
|
|||
|
||||
void checkSocketRecvBuffer();
|
||||
|
||||
void addCommandSelf();
|
||||
protected:
|
||||
virtual bool prepareForRetry(time_t wait);
|
||||
virtual void onAbort();
|
||||
|
|
|
@ -126,7 +126,7 @@ bool AbstractHttpServerResponseCommand::execute()
|
|||
return true;
|
||||
} else {
|
||||
updateReadWriteCheck();
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ bool AbstractProxyRequestCommand::executeInternal() {
|
|||
return true;
|
||||
} else {
|
||||
setWriteCheckSocket(getSocket());
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
|
||||
virtual ~AbstractProxyRequestCommand();
|
||||
|
||||
virtual Command* getNextCommand() = 0;
|
||||
virtual std::unique_ptr<Command> getNextCommand() = 0;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -67,7 +67,7 @@ bool AbstractProxyResponseCommand::executeInternal() {
|
|||
std::shared_ptr<HttpResponse> httpResponse = httpConnection_->receiveResponse();
|
||||
if(!httpResponse) {
|
||||
// the server has not responded our request yet.
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
if(httpResponse->getStatusCode() != 200) {
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
virtual ~AbstractProxyResponseCommand();
|
||||
|
||||
virtual Command* getNextCommand() = 0;
|
||||
virtual std::unique_ptr<Command> getNextCommand() = 0;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -123,7 +123,7 @@ bool ActivePeerConnectionCommand::execute() {
|
|||
}
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -136,12 +136,11 @@ void ActivePeerConnectionCommand::makeNewConnections(int num)
|
|||
if(!peer) {
|
||||
break;
|
||||
}
|
||||
PeerInitiateConnectionCommand* command;
|
||||
command = new PeerInitiateConnectionCommand(ncuid, requestGroup_, peer, e_,
|
||||
btRuntime_);
|
||||
auto command = make_unique<PeerInitiateConnectionCommand>
|
||||
(ncuid, requestGroup_, peer, e_, btRuntime_);
|
||||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(std::move(command));
|
||||
A2_LOG_INFO(fmt(MSG_CONNECTING_TO_PEER, getCuid(),
|
||||
peer->getIPAddress().c_str()));
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ bool BackupIPv4ConnectCommand::execute()
|
|||
retval = true;
|
||||
}
|
||||
if(!retval) {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ BtCheckIntegrityEntry::BtCheckIntegrityEntry(RequestGroup* requestGroup):
|
|||
BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
|
||||
|
||||
void BtCheckIntegrityEntry::onDownloadIncomplete
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
const std::shared_ptr<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
|
||||
ps->onDownloadIncomplete();
|
||||
|
@ -69,7 +69,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete
|
|||
}
|
||||
|
||||
void BtCheckIntegrityEntry::onDownloadFinished
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
// TODO Currently,when all the checksums
|
||||
// are valid, then aira2 goes to seeding mode. Sometimes it is better
|
||||
|
|
|
@ -45,11 +45,11 @@ public:
|
|||
|
||||
virtual ~BtCheckIntegrityEntry();
|
||||
|
||||
virtual void onDownloadFinished(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadFinished
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e);
|
||||
|
||||
virtual void onDownloadIncomplete(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadIncomplete
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -56,7 +56,7 @@ BtFileAllocationEntry::BtFileAllocationEntry(RequestGroup* requestGroup):
|
|||
BtFileAllocationEntry::~BtFileAllocationEntry() {}
|
||||
|
||||
void BtFileAllocationEntry::prepareForNextAction
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
BtSetup().setup(commands, getRequestGroup(), e,
|
||||
getRequestGroup()->getOption().get());
|
||||
|
|
|
@ -45,8 +45,8 @@ public:
|
|||
|
||||
virtual ~BtFileAllocationEntry();
|
||||
|
||||
virtual void prepareForNextAction(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void prepareForNextAction
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace aria2 {
|
|||
|
||||
BtSetup::BtSetup() {}
|
||||
|
||||
void BtSetup::setup(std::vector<Command*>& commands,
|
||||
void BtSetup::setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
const Option* option)
|
||||
|
@ -109,53 +109,50 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
const std::shared_ptr<BtAnnounce>& btAnnounce = btObject->btAnnounce;
|
||||
// commands
|
||||
{
|
||||
TrackerWatcherCommand* c =
|
||||
new TrackerWatcherCommand(e->newCUID(), requestGroup, e);
|
||||
auto c = make_unique<TrackerWatcherCommand>(e->newCUID(), requestGroup, e);
|
||||
c->setPeerStorage(peerStorage);
|
||||
c->setPieceStorage(pieceStorage);
|
||||
c->setBtRuntime(btRuntime);
|
||||
c->setBtAnnounce(btAnnounce);
|
||||
|
||||
commands.push_back(c);
|
||||
commands.push_back(std::move(c));
|
||||
}
|
||||
if(!metadataGetMode) {
|
||||
PeerChokeCommand* c =
|
||||
new PeerChokeCommand(e->newCUID(), e);
|
||||
auto c = make_unique<PeerChokeCommand>(e->newCUID(), e);
|
||||
c->setPeerStorage(peerStorage);
|
||||
c->setBtRuntime(btRuntime);
|
||||
|
||||
commands.push_back(c);
|
||||
commands.push_back(std::move(c));
|
||||
}
|
||||
{
|
||||
ActivePeerConnectionCommand* c =
|
||||
new ActivePeerConnectionCommand(e->newCUID(), requestGroup, e,
|
||||
metadataGetMode?2:10);
|
||||
auto c = make_unique<ActivePeerConnectionCommand>
|
||||
(e->newCUID(), requestGroup, e, metadataGetMode?2:10);
|
||||
c->setBtRuntime(btRuntime);
|
||||
c->setPieceStorage(pieceStorage);
|
||||
c->setPeerStorage(peerStorage);
|
||||
c->setBtAnnounce(btAnnounce);
|
||||
|
||||
commands.push_back(c);
|
||||
commands.push_back(std::move(c));
|
||||
}
|
||||
|
||||
if(metadataGetMode || !torrentAttrs->privateTorrent) {
|
||||
if(DHTRegistry::isInitialized()) {
|
||||
DHTGetPeersCommand* command =
|
||||
new DHTGetPeersCommand(e->newCUID(), requestGroup, e);
|
||||
auto command = make_unique<DHTGetPeersCommand>
|
||||
(e->newCUID(), requestGroup, e);
|
||||
command->setTaskQueue(DHTRegistry::getData().taskQueue);
|
||||
command->setTaskFactory(DHTRegistry::getData().taskFactory);
|
||||
command->setBtRuntime(btRuntime);
|
||||
command->setPeerStorage(peerStorage);
|
||||
commands.push_back(command);
|
||||
commands.push_back(std::move(command));
|
||||
}
|
||||
if(DHTRegistry::isInitialized6()) {
|
||||
DHTGetPeersCommand* command =
|
||||
new DHTGetPeersCommand(e->newCUID(), requestGroup, e);
|
||||
auto command = make_unique<DHTGetPeersCommand>
|
||||
(e->newCUID(), requestGroup, e);
|
||||
command->setTaskQueue(DHTRegistry::getData6().taskQueue);
|
||||
command->setTaskFactory(DHTRegistry::getData6().taskFactory);
|
||||
command->setBtRuntime(btRuntime);
|
||||
command->setPeerStorage(peerStorage);
|
||||
commands.push_back(command);
|
||||
commands.push_back(std::move(command));
|
||||
}
|
||||
}
|
||||
if(!metadataGetMode) {
|
||||
|
@ -178,19 +175,19 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
}
|
||||
}
|
||||
if(!unionCri->getSeedCriterion().empty()) {
|
||||
SeedCheckCommand* c =
|
||||
new SeedCheckCommand(e->newCUID(), requestGroup, e, unionCri);
|
||||
auto c = make_unique<SeedCheckCommand>
|
||||
(e->newCUID(), requestGroup, e, unionCri);
|
||||
c->setPieceStorage(pieceStorage);
|
||||
c->setBtRuntime(btRuntime);
|
||||
commands.push_back(c);
|
||||
commands.push_back(std::move(c));
|
||||
}
|
||||
}
|
||||
if(btReg->getTcpPort() == 0) {
|
||||
static int families[] = { AF_INET, AF_INET6 };
|
||||
size_t familiesLength = e->getOption()->getAsBool(PREF_DISABLE_IPV6)?1:2;
|
||||
for(size_t i = 0; i < familiesLength; ++i) {
|
||||
PeerListenCommand* command =
|
||||
new PeerListenCommand(e->newCUID(), e, families[i]);
|
||||
auto command = make_unique<PeerListenCommand>
|
||||
(e->newCUID(), e, families[i]);
|
||||
bool ret;
|
||||
uint16_t port;
|
||||
if(btReg->getTcpPort()) {
|
||||
|
@ -207,9 +204,7 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
if(ret) {
|
||||
btReg->setTcpPort(port);
|
||||
// Add command to DownloadEngine directly.
|
||||
e->addCommand(command);
|
||||
} else {
|
||||
delete command;
|
||||
e->addCommand(std::move(command));
|
||||
}
|
||||
}
|
||||
if(btReg->getTcpPort() == 0) {
|
||||
|
@ -252,9 +247,8 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
" localAddr=%s",
|
||||
LPD_MULTICAST_ADDR, LPD_MULTICAST_PORT,
|
||||
receiver->getLocalAddress().c_str()));
|
||||
LpdReceiveMessageCommand* cmd =
|
||||
new LpdReceiveMessageCommand(e->newCUID(), receiver, e);
|
||||
e->addCommand(cmd);
|
||||
e->addCommand(make_unique<LpdReceiveMessageCommand>
|
||||
(e->newCUID(), receiver, e));
|
||||
} else {
|
||||
A2_LOG_INFO("LpdMessageReceiver not initialized.");
|
||||
}
|
||||
|
@ -271,10 +265,10 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
if(dispatcher->init(btReg->getLpdMessageReceiver()->getLocalAddress(),
|
||||
/*ttl*/1, /*loop*/1)) {
|
||||
A2_LOG_INFO("LpdMessageDispatcher initialized.");
|
||||
LpdDispatchMessageCommand* cmd =
|
||||
new LpdDispatchMessageCommand(e->newCUID(), dispatcher, e);
|
||||
auto cmd = make_unique<LpdDispatchMessageCommand>
|
||||
(e->newCUID(), dispatcher, e);
|
||||
cmd->setBtRuntime(btRuntime);
|
||||
e->addCommand(cmd);
|
||||
e->addCommand(std::move(cmd));
|
||||
} else {
|
||||
A2_LOG_INFO("LpdMessageDispatcher not initialized.");
|
||||
}
|
||||
|
@ -282,11 +276,11 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
}
|
||||
time_t btStopTimeout = option->getAsInt(PREF_BT_STOP_TIMEOUT);
|
||||
if(btStopTimeout > 0) {
|
||||
BtStopDownloadCommand* stopDownloadCommand =
|
||||
new BtStopDownloadCommand(e->newCUID(), requestGroup, e, btStopTimeout);
|
||||
auto stopDownloadCommand = make_unique<BtStopDownloadCommand>
|
||||
(e->newCUID(), requestGroup, e, btStopTimeout);
|
||||
stopDownloadCommand->setBtRuntime(btRuntime);
|
||||
stopDownloadCommand->setPieceStorage(pieceStorage);
|
||||
commands.push_back(stopDownloadCommand);
|
||||
commands.push_back(std::move(stopDownloadCommand));
|
||||
}
|
||||
btRuntime->setReady(true);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
#define D_BT_SETUP_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -49,7 +51,7 @@ class BtSetup {
|
|||
public:
|
||||
BtSetup();
|
||||
|
||||
void setup(std::vector<Command*>& commands,
|
||||
void setup(std::vector<std::unique_ptr<Command>>& commands,
|
||||
RequestGroup* requestGroup,
|
||||
DownloadEngine* e,
|
||||
const Option* option);
|
||||
|
|
|
@ -74,25 +74,21 @@ bool CheckIntegrityCommand::executeInternal()
|
|||
A2_LOG_NOTICE
|
||||
(fmt(MSG_VERIFICATION_SUCCESSFUL,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
entry_->onDownloadFinished(*commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(*commands);
|
||||
commands->clear();
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
entry_->onDownloadFinished(commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(std::move(commands));
|
||||
} else {
|
||||
A2_LOG_ERROR
|
||||
(fmt(MSG_VERIFICATION_FAILED,
|
||||
getRequestGroup()->getDownloadContext()->getBasePath().c_str()));
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
entry_->onDownloadIncomplete(*commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(*commands);
|
||||
commands->clear();
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
entry_->onDownloadIncomplete(commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(std::move(commands));
|
||||
}
|
||||
getDownloadEngine()->setNoWait(true);
|
||||
return true;
|
||||
} else {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
getDownloadEngine()->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,13 +52,13 @@ CheckIntegrityDispatcherCommand::CheckIntegrityDispatcherCommand
|
|||
setStatusRealtime();
|
||||
}
|
||||
|
||||
Command* CheckIntegrityDispatcherCommand::createCommand
|
||||
std::unique_ptr<Command> CheckIntegrityDispatcherCommand::createCommand
|
||||
(const std::shared_ptr<CheckIntegrityEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Dispatching CheckIntegrityCommand CUID#%" PRId64 ".",
|
||||
getCuid(), newCUID));
|
||||
return new CheckIntegrityCommand
|
||||
return make_unique<CheckIntegrityCommand>
|
||||
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
const std::shared_ptr<CheckIntegrityMan>& checkMan,
|
||||
DownloadEngine* e);
|
||||
protected:
|
||||
virtual Command* createCommand
|
||||
virtual std::unique_ptr<Command> createCommand
|
||||
(const std::shared_ptr<CheckIntegrityEntry>& entry);
|
||||
};
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
namespace aria2 {
|
||||
|
||||
CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand):
|
||||
RequestGroupEntry(requestGroup, nextCommand)
|
||||
std::unique_ptr<Command> nextCommand):
|
||||
RequestGroupEntry(requestGroup, std::move(nextCommand))
|
||||
{}
|
||||
|
||||
CheckIntegrityEntry::~CheckIntegrityEntry() {}
|
||||
|
@ -85,7 +85,7 @@ void CheckIntegrityEntry::cutTrailingGarbage()
|
|||
}
|
||||
|
||||
void CheckIntegrityEntry::proceedFileAllocation
|
||||
(std::vector<Command*>& commands,
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
const std::shared_ptr<FileAllocationEntry>& entry,
|
||||
DownloadEngine* e)
|
||||
{
|
||||
|
|
|
@ -55,11 +55,13 @@ private:
|
|||
protected:
|
||||
void setValidator(const std::shared_ptr<IteratableValidator>& validator);
|
||||
|
||||
void proceedFileAllocation(std::vector<Command*>& commands,
|
||||
void proceedFileAllocation(std::vector<std::unique_ptr<Command>>& commands,
|
||||
const std::shared_ptr<FileAllocationEntry>& entry,
|
||||
DownloadEngine* e);
|
||||
public:
|
||||
CheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
|
||||
CheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~CheckIntegrityEntry();
|
||||
|
||||
|
@ -75,11 +77,13 @@ public:
|
|||
|
||||
virtual void initValidator() = 0;
|
||||
|
||||
virtual void onDownloadFinished(std::vector<Command*>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
virtual void onDownloadFinished
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
|
||||
virtual void onDownloadIncomplete(std::vector<Command*>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
virtual void onDownloadIncomplete
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
|
||||
void cutTrailingGarbage();
|
||||
};
|
||||
|
|
|
@ -44,8 +44,9 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand):
|
||||
CheckIntegrityEntry(requestGroup, nextCommand),
|
||||
ChecksumCheckIntegrityEntry::ChecksumCheckIntegrityEntry
|
||||
(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand):
|
||||
CheckIntegrityEntry(requestGroup, std::move(nextCommand)),
|
||||
redownload_(false) {}
|
||||
|
||||
ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
|
||||
|
@ -68,12 +69,12 @@ void ChecksumCheckIntegrityEntry::initValidator()
|
|||
|
||||
void
|
||||
ChecksumCheckIntegrityEntry::onDownloadFinished
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{}
|
||||
|
||||
void
|
||||
ChecksumCheckIntegrityEntry::onDownloadIncomplete
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
if(redownload_) {
|
||||
std::shared_ptr<FileAllocationEntry> entry
|
||||
|
|
|
@ -44,7 +44,9 @@ class ChecksumCheckIntegrityEntry:public CheckIntegrityEntry
|
|||
private:
|
||||
bool redownload_;
|
||||
public:
|
||||
ChecksumCheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
|
||||
ChecksumCheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~ChecksumCheckIntegrityEntry();
|
||||
|
||||
|
@ -52,11 +54,13 @@ public:
|
|||
|
||||
virtual void initValidator();
|
||||
|
||||
virtual void onDownloadFinished(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadFinished
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e);
|
||||
|
||||
virtual void onDownloadIncomplete(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadIncomplete
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e);
|
||||
|
||||
void setRedownload(bool redownload)
|
||||
{
|
||||
|
|
|
@ -105,16 +105,15 @@ bool CreateRequestCommand::executeInternal()
|
|||
// counted (1 for pooled and another one in this command) and
|
||||
// AbstractCommand::execute() will behave badly.
|
||||
resetRequest();
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
|
||||
Command* command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
getDownloadEngine());
|
||||
getDownloadEngine()->setNoWait(true);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand
|
||||
(InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
getDownloadEngine()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ bool DHTEntryPointNameResolveCommand::execute()
|
|||
std::vector<std::string> res;
|
||||
int rv = resolveHostname(res, hostname);
|
||||
if(rv == 0) {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
} else {
|
||||
if(rv == 1) {
|
||||
|
|
|
@ -126,7 +126,7 @@ bool DHTGetPeersCommand::execute()
|
|||
task_.reset();
|
||||
}
|
||||
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ bool DHTInteractionCommand::execute()
|
|||
udpTrackerClient_->requestFail(UDPT_ERR_NETWORK);
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,21 +78,17 @@ DHTSetup::DHTSetup() {}
|
|||
|
||||
DHTSetup::~DHTSetup() {}
|
||||
|
||||
void DHTSetup::setup
|
||||
(std::vector<Command*>& commands, DownloadEngine* e, int family)
|
||||
std::vector<std::unique_ptr<Command>> DHTSetup::setup
|
||||
(DownloadEngine* e, int family)
|
||||
{
|
||||
if(family != AF_INET && family != AF_INET6) {
|
||||
return;
|
||||
}
|
||||
if((family == AF_INET && DHTRegistry::isInitialized()) ||
|
||||
std::vector<std::unique_ptr<Command> > tempCommands;
|
||||
if((family != AF_INET && family != AF_INET6) ||
|
||||
(family == AF_INET && DHTRegistry::isInitialized()) ||
|
||||
(family == AF_INET6 && DHTRegistry::isInitialized6())) {
|
||||
return;
|
||||
return tempCommands;
|
||||
}
|
||||
try {
|
||||
std::vector<Command*>* tempCommands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(tempCommands);
|
||||
// load routing table and localnode id here
|
||||
|
||||
std::shared_ptr<DHTNode> localNode;
|
||||
|
||||
DHTRoutingTableDeserializer deserializer(family);
|
||||
|
@ -240,65 +236,60 @@ void DHTSetup::setup
|
|||
e->getOption()->getAsInt(prefEntryPointPort));
|
||||
std::vector<std::pair<std::string, uint16_t> > entryPoints;
|
||||
entryPoints.push_back(addr);
|
||||
DHTEntryPointNameResolveCommand* command =
|
||||
new DHTEntryPointNameResolveCommand(e->newCUID(), e, entryPoints);
|
||||
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
||||
(e->newCUID(), e, entryPoints);
|
||||
command->setBootstrapEnabled(true);
|
||||
command->setTaskQueue(taskQueue);
|
||||
command->setTaskFactory(taskFactory);
|
||||
command->setRoutingTable(routingTable);
|
||||
command->setLocalNode(localNode);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
} else {
|
||||
A2_LOG_INFO("No DHT entry point specified.");
|
||||
}
|
||||
{
|
||||
DHTInteractionCommand* command =
|
||||
new DHTInteractionCommand(e->newCUID(), e);
|
||||
auto command = make_unique<DHTInteractionCommand>(e->newCUID(), e);
|
||||
command->setMessageDispatcher(dispatcher);
|
||||
command->setMessageReceiver(receiver);
|
||||
command->setTaskQueue(taskQueue);
|
||||
command->setReadCheckSocket(connection->getSocket());
|
||||
command->setConnection(connection);
|
||||
command->setUDPTrackerClient(udpTrackerClient);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
{
|
||||
DHTTokenUpdateCommand* command =
|
||||
new DHTTokenUpdateCommand(e->newCUID(), e, DHT_TOKEN_UPDATE_INTERVAL);
|
||||
auto command = make_unique<DHTTokenUpdateCommand>
|
||||
(e->newCUID(), e, DHT_TOKEN_UPDATE_INTERVAL);
|
||||
command->setTokenTracker(tokenTracker);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
{
|
||||
DHTBucketRefreshCommand* command =
|
||||
new DHTBucketRefreshCommand(e->newCUID(), e,
|
||||
DHT_BUCKET_REFRESH_CHECK_INTERVAL);
|
||||
auto command = make_unique<DHTBucketRefreshCommand>
|
||||
(e->newCUID(), e, DHT_BUCKET_REFRESH_CHECK_INTERVAL);
|
||||
command->setTaskQueue(taskQueue);
|
||||
command->setRoutingTable(routingTable);
|
||||
command->setTaskFactory(taskFactory);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
{
|
||||
DHTPeerAnnounceCommand* command =
|
||||
new DHTPeerAnnounceCommand(e->newCUID(), e,
|
||||
DHT_PEER_ANNOUNCE_CHECK_INTERVAL);
|
||||
auto command = make_unique<DHTPeerAnnounceCommand>
|
||||
(e->newCUID(), e, DHT_PEER_ANNOUNCE_CHECK_INTERVAL);
|
||||
command->setPeerAnnounceStorage(peerAnnounceStorage);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
{
|
||||
DHTAutoSaveCommand* command =
|
||||
new DHTAutoSaveCommand(e->newCUID(), e, family, 30*60);
|
||||
auto command = make_unique<DHTAutoSaveCommand>
|
||||
(e->newCUID(), e, family, 30*60);
|
||||
command->setLocalNode(localNode);
|
||||
command->setRoutingTable(routingTable);
|
||||
tempCommands->push_back(command);
|
||||
tempCommands.push_back(std::move(command));
|
||||
}
|
||||
if(family == AF_INET) {
|
||||
DHTRegistry::setInitialized(true);
|
||||
} else {
|
||||
DHTRegistry::setInitialized6(true);
|
||||
}
|
||||
commands.insert(commands.end(), tempCommands->begin(), tempCommands->end());
|
||||
tempCommands->clear();
|
||||
if(e->getBtRegistry()->getUdpPort() == 0) {
|
||||
// We assign port last so that no exception gets in the way
|
||||
e->getBtRegistry()->setUdpPort(port);
|
||||
|
@ -307,6 +298,7 @@ void DHTSetup::setup
|
|||
A2_LOG_ERROR_EX(fmt("Exception caught while initializing DHT functionality."
|
||||
" DHT is disabled."),
|
||||
ex);
|
||||
tempCommands.clear();
|
||||
if(family == AF_INET) {
|
||||
DHTRegistry::clearData();
|
||||
e->getBtRegistry()->setUDPTrackerClient
|
||||
|
@ -315,6 +307,7 @@ void DHTSetup::setup
|
|||
DHTRegistry::clearData6();
|
||||
}
|
||||
}
|
||||
return tempCommands;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -36,7 +36,9 @@
|
|||
#define D_DHT_SETUP_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -49,7 +51,7 @@ public:
|
|||
|
||||
~DHTSetup();
|
||||
|
||||
void setup(std::vector<Command*>& commands, DownloadEngine* e, int family);
|
||||
std::vector<std::unique_ptr<Command>> setup(DownloadEngine* e, int family);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -143,7 +143,7 @@ void flushWrDiskCacheEntry(WrDiskCache* wrDiskCache,
|
|||
bool DownloadCommand::executeInternal() {
|
||||
if(getDownloadEngine()->getRequestGroupMan()->doesOverallDownloadSpeedExceed()
|
||||
|| getRequestGroup()->doesDownloadSpeedExceed()) {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
disableReadCheckSocket();
|
||||
return false;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ bool DownloadCommand::executeInternal() {
|
|||
checkLowestDownloadSpeed();
|
||||
setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
|
||||
checkSocketRecvBuffer();
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ bool DownloadCommand::prepareForNextSegment() {
|
|||
return prepareForRetry(0);
|
||||
} else {
|
||||
checkSocketRecvBuffer();
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <cerrno>
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#include <iterator>
|
||||
|
||||
#include "StatCalc.h"
|
||||
#include "RequestGroup.h"
|
||||
|
@ -107,40 +108,32 @@ DownloadEngine::DownloadEngine(const std::shared_ptr<EventPoll>& eventPoll)
|
|||
sessionId_.assign(&sessionId[0], & sessionId[sizeof(sessionId)]);
|
||||
}
|
||||
|
||||
namespace {
|
||||
void cleanQueue(std::deque<Command*>& commands) {
|
||||
std::for_each(commands.begin(), commands.end(), Deleter());
|
||||
commands.clear();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DownloadEngine::~DownloadEngine() {
|
||||
cleanQueue(commands_);
|
||||
cleanQueue(routineCommands_);
|
||||
DownloadEngine::~DownloadEngine()
|
||||
{
|
||||
#ifdef HAVE_ARES_ADDR_NODE
|
||||
setAsyncDNSServers(0);
|
||||
#endif // HAVE_ARES_ADDR_NODE
|
||||
}
|
||||
|
||||
namespace {
|
||||
void executeCommand(std::deque<Command*>& commands,
|
||||
void executeCommand(std::deque<std::unique_ptr<Command>>& commands,
|
||||
Command::STATUS statusFilter)
|
||||
{
|
||||
size_t max = commands.size();
|
||||
for(size_t i = 0; i < max; ++i) {
|
||||
Command* com = commands.front();
|
||||
std::unique_ptr<Command> com = std::move(commands.front());
|
||||
commands.pop_front();
|
||||
if(com->statusMatch(statusFilter)) {
|
||||
com->transitStatus();
|
||||
if(com->execute()) {
|
||||
delete com;
|
||||
com = 0;
|
||||
com.reset();
|
||||
} else {
|
||||
com->clearIOEvents();
|
||||
com.release();
|
||||
}
|
||||
} else {
|
||||
commands.push_back(com);
|
||||
}
|
||||
if(com) {
|
||||
com->clearIOEvents();
|
||||
commands.push_back(std::move(com));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -282,9 +275,9 @@ void DownloadEngine::setNoWait(bool b)
|
|||
noWait_ = b;
|
||||
}
|
||||
|
||||
void DownloadEngine::addRoutineCommand(Command* command)
|
||||
void DownloadEngine::addRoutineCommand(std::unique_ptr<Command> command)
|
||||
{
|
||||
routineCommands_.push_back(command);
|
||||
routineCommands_.push_back(std::move(command));
|
||||
}
|
||||
|
||||
void DownloadEngine::poolSocket(const std::string& key,
|
||||
|
@ -561,14 +554,17 @@ void DownloadEngine::setRefreshInterval(int64_t interval)
|
|||
refreshInterval_ = std::min(static_cast<int64_t>(999), interval);
|
||||
}
|
||||
|
||||
void DownloadEngine::addCommand(const std::vector<Command*>& commands)
|
||||
void DownloadEngine::addCommand
|
||||
(std::vector<std::unique_ptr<Command>> commands)
|
||||
{
|
||||
commands_.insert(commands_.end(), commands.begin(), commands.end());
|
||||
commands_.insert(commands_.end(),
|
||||
std::make_move_iterator(std::begin(commands)),
|
||||
std::make_move_iterator(std::end(commands)));
|
||||
}
|
||||
|
||||
void DownloadEngine::addCommand(Command* command)
|
||||
void DownloadEngine::addCommand(std::unique_ptr<Command> command)
|
||||
{
|
||||
commands_.push_back(command);
|
||||
commands_.push_back(std::move(command));
|
||||
}
|
||||
|
||||
void DownloadEngine::setRequestGroupMan
|
||||
|
|
|
@ -131,7 +131,7 @@ private:
|
|||
int64_t refreshInterval_;
|
||||
Timer lastRefresh_;
|
||||
|
||||
std::deque<Command*> routineCommands_;
|
||||
std::deque<std::unique_ptr<Command>> routineCommands_;
|
||||
|
||||
std::shared_ptr<CookieStorage> cookieStorage_;
|
||||
|
||||
|
@ -167,7 +167,7 @@ private:
|
|||
std::multimap<std::string, SocketPoolEntry>::iterator
|
||||
findSocketPoolEntry(const std::string& key);
|
||||
|
||||
std::deque<Command*> commands_;
|
||||
std::deque<std::unique_ptr<Command>> commands_;
|
||||
std::shared_ptr<RequestGroupMan> requestGroupMan_;
|
||||
std::shared_ptr<FileAllocationMan> fileAllocationMan_;
|
||||
std::shared_ptr<CheckIntegrityMan> checkIntegrityMan_;
|
||||
|
@ -200,9 +200,9 @@ public:
|
|||
Command* command);
|
||||
#endif // ENABLE_ASYNC_DNS
|
||||
|
||||
void addCommand(const std::vector<Command*>& commands);
|
||||
void addCommand(std::vector<std::unique_ptr<Command>> commands);
|
||||
|
||||
void addCommand(Command* command);
|
||||
void addCommand(std::unique_ptr<Command> command);
|
||||
|
||||
const std::shared_ptr<RequestGroupMan>& getRequestGroupMan() const
|
||||
{
|
||||
|
@ -253,7 +253,7 @@ public:
|
|||
|
||||
void setNoWait(bool b);
|
||||
|
||||
void addRoutineCommand(Command* command);
|
||||
void addRoutineCommand(std::unique_ptr<Command> command);
|
||||
|
||||
void poolSocket(const std::string& ipaddr, uint16_t port,
|
||||
const std::string& username,
|
||||
|
|
|
@ -159,35 +159,38 @@ DownloadEngineFactory::newDownloadEngine
|
|||
e->setCheckIntegrityMan
|
||||
(std::shared_ptr<CheckIntegrityMan>(new CheckIntegrityMan()));
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
e->addRoutineCommand(new FillRequestGroupCommand(e->newCUID(), e.get()));
|
||||
e->addRoutineCommand(new FileAllocationDispatcherCommand
|
||||
e->addRoutineCommand(make_unique<FillRequestGroupCommand>
|
||||
(e->newCUID(), e.get()));
|
||||
e->addRoutineCommand(make_unique<FileAllocationDispatcherCommand>
|
||||
(e->newCUID(), e->getFileAllocationMan(), e.get()));
|
||||
#ifdef ENABLE_MESSAGE_DIGEST
|
||||
e->addRoutineCommand(new CheckIntegrityDispatcherCommand
|
||||
e->addRoutineCommand(make_unique<CheckIntegrityDispatcherCommand>
|
||||
(e->newCUID(), e->getCheckIntegrityMan(), e.get()));
|
||||
#endif // ENABLE_MESSAGE_DIGEST
|
||||
|
||||
if(op->getAsInt(PREF_AUTO_SAVE_INTERVAL) > 0) {
|
||||
e->addRoutineCommand
|
||||
(new AutoSaveCommand(e->newCUID(), e.get(),
|
||||
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
||||
(make_unique<AutoSaveCommand>(e->newCUID(), e.get(),
|
||||
op->getAsInt(PREF_AUTO_SAVE_INTERVAL)));
|
||||
}
|
||||
if(op->getAsInt(PREF_SAVE_SESSION_INTERVAL) > 0) {
|
||||
e->addRoutineCommand
|
||||
(new SaveSessionCommand(e->newCUID(), e.get(),
|
||||
op->getAsInt(PREF_SAVE_SESSION_INTERVAL)));
|
||||
e->addRoutineCommand(make_unique<SaveSessionCommand>
|
||||
(e->newCUID(), e.get(),
|
||||
op->getAsInt(PREF_SAVE_SESSION_INTERVAL)));
|
||||
}
|
||||
e->addRoutineCommand(new HaveEraseCommand(e->newCUID(), e.get(), 10));
|
||||
e->addRoutineCommand(make_unique<HaveEraseCommand>
|
||||
(e->newCUID(), e.get(), 10));
|
||||
{
|
||||
time_t stopSec = op->getAsInt(PREF_STOP);
|
||||
if(stopSec > 0) {
|
||||
e->addRoutineCommand(new TimedHaltCommand(e->newCUID(), e.get(),
|
||||
stopSec));
|
||||
e->addRoutineCommand(make_unique<TimedHaltCommand>(e->newCUID(), e.get(),
|
||||
stopSec));
|
||||
}
|
||||
}
|
||||
if(op->defined(PREF_STOP_WITH_PROCESS)) {
|
||||
unsigned int pid = op->getAsInt(PREF_STOP_WITH_PROCESS);
|
||||
e->addRoutineCommand(new WatchProcessCommand(e->newCUID(), e.get(), pid));
|
||||
e->addRoutineCommand(make_unique<WatchProcessCommand>(e->newCUID(),
|
||||
e.get(), pid));
|
||||
}
|
||||
if(op->getAsBool(PREF_ENABLE_RPC)) {
|
||||
bool ok = false;
|
||||
|
@ -198,13 +201,11 @@ DownloadEngineFactory::newDownloadEngine
|
|||
static int families[] = { AF_INET, AF_INET6 };
|
||||
size_t familiesLength = op->getAsBool(PREF_DISABLE_IPV6)?1:2;
|
||||
for(size_t i = 0; i < familiesLength; ++i) {
|
||||
HttpListenCommand* httpListenCommand =
|
||||
new HttpListenCommand(e->newCUID(), e.get(), families[i], secure);
|
||||
auto httpListenCommand = make_unique<HttpListenCommand>
|
||||
(e->newCUID(), e.get(), families[i], secure);
|
||||
if(httpListenCommand->bindPort(op->getAsInt(PREF_RPC_LISTEN_PORT))){
|
||||
e->addCommand(httpListenCommand);
|
||||
e->addCommand(std::move(httpListenCommand));
|
||||
ok = true;
|
||||
} else {
|
||||
delete httpListenCommand;
|
||||
}
|
||||
}
|
||||
if(!ok) {
|
||||
|
|
|
@ -74,15 +74,13 @@ bool FileAllocationCommand::executeInternal()
|
|||
getRequestGroup()->getTotalLength()));
|
||||
getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
|
||||
|
||||
std::vector<Command*>* commands = new std::vector<Command*>();
|
||||
auto_delete_container<std::vector<Command*> > commandsDel(commands);
|
||||
fileAllocationEntry_->prepareForNextAction(*commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(*commands);
|
||||
commands->clear();
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
fileAllocationEntry_->prepareForNextAction(commands, getDownloadEngine());
|
||||
getDownloadEngine()->addCommand(std::move(commands));
|
||||
getDownloadEngine()->setNoWait(true);
|
||||
return true;
|
||||
} else {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
getDownloadEngine()->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,15 +50,13 @@ FileAllocationDispatcherCommand::FileAllocationDispatcherCommand
|
|||
: SequentialDispatcherCommand<FileAllocationEntry>(cuid, fileAllocMan, e)
|
||||
{}
|
||||
|
||||
Command* FileAllocationDispatcherCommand::createCommand
|
||||
std::unique_ptr<Command> FileAllocationDispatcherCommand::createCommand
|
||||
(const std::shared_ptr<FileAllocationEntry>& entry)
|
||||
{
|
||||
cuid_t newCUID = getDownloadEngine()->newCUID();
|
||||
A2_LOG_INFO(fmt(MSG_FILE_ALLOCATION_DISPATCH, newCUID));
|
||||
FileAllocationCommand* command =
|
||||
new FileAllocationCommand(newCUID, entry->getRequestGroup(),
|
||||
getDownloadEngine(), entry);
|
||||
return command;
|
||||
return make_unique<FileAllocationCommand>
|
||||
(newCUID, entry->getRequestGroup(), getDownloadEngine(), entry);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
const std::shared_ptr<FileAllocationMan>& fileAllocMan,
|
||||
DownloadEngine* e);
|
||||
protected:
|
||||
virtual Command* createCommand
|
||||
virtual std::unique_ptr<Command> createCommand
|
||||
(const std::shared_ptr<FileAllocationEntry>& entry);
|
||||
};
|
||||
|
||||
|
|
|
@ -41,8 +41,9 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand):
|
||||
RequestGroupEntry(requestGroup, nextCommand),
|
||||
FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup,
|
||||
std::unique_ptr<Command> nextCommand):
|
||||
RequestGroupEntry(requestGroup, std::move(nextCommand)),
|
||||
fileAllocationIterator_(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator())
|
||||
{}
|
||||
|
||||
|
|
|
@ -52,7 +52,9 @@ class FileAllocationEntry : public RequestGroupEntry, public ProgressAwareEntry
|
|||
private:
|
||||
std::shared_ptr<FileAllocationIterator> fileAllocationIterator_;
|
||||
public:
|
||||
FileAllocationEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
|
||||
FileAllocationEntry(RequestGroup* requestGroup,
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
~FileAllocationEntry();
|
||||
|
||||
|
@ -64,8 +66,9 @@ public:
|
|||
|
||||
void allocateChunk();
|
||||
|
||||
virtual void prepareForNextAction(std::vector<Command*>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
virtual void prepareForNextAction
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e) = 0;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -80,7 +80,7 @@ bool FillRequestGroupCommand::execute()
|
|||
return true;
|
||||
}
|
||||
}
|
||||
e_->addRoutineCommand(this);
|
||||
e_->addRoutineCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,10 +70,10 @@ bool FtpDownloadCommand::prepareForNextSegment()
|
|||
if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) &&
|
||||
getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) ==
|
||||
getFileEntry()->getLength()) {
|
||||
Command* command = new FtpFinishDownloadCommand
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
ftpConnection_, getDownloadEngine(), ctrlSocket_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand
|
||||
(make_unique<FtpFinishDownloadCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
ftpConnection_, getDownloadEngine(), ctrlSocket_));
|
||||
|
||||
if(getRequestGroup()->downloadFinished()) {
|
||||
// To run checksum checking, we had to call following function here.
|
||||
|
|
|
@ -80,7 +80,7 @@ bool FtpFinishDownloadCommand::execute()
|
|||
getCheckPoint() = global::wallclock();
|
||||
int status = ftpConnection_->receiveResponse();
|
||||
if(status == 0) {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
if(status == 226) {
|
||||
|
@ -97,7 +97,7 @@ bool FtpFinishDownloadCommand::execute()
|
|||
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Timeout before receiving transfer complete.",
|
||||
getCuid()));
|
||||
} else {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
|
|
|
@ -73,12 +73,11 @@ FtpInitiateConnectionCommand::FtpInitiateConnectionCommand
|
|||
|
||||
FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {}
|
||||
|
||||
Command* FtpInitiateConnectionCommand::createNextCommand
|
||||
std::unique_ptr<Command> FtpInitiateConnectionCommand::createNextCommand
|
||||
(const std::string& hostname, const std::string& addr, uint16_t port,
|
||||
const std::vector<std::string>& resolvedAddresses,
|
||||
const std::shared_ptr<Request>& proxyRequest)
|
||||
{
|
||||
Command* command;
|
||||
if(proxyRequest) {
|
||||
std::string options;
|
||||
std::shared_ptr<SocketCore> pooledSocket;
|
||||
|
@ -102,13 +101,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
|
||||
getRequest()->setConnectedAddrInfo(hostname, addr, port);
|
||||
|
||||
ConnectCommand* c = new ConnectCommand(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest,
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
auto c = make_unique<ConnectCommand>(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest,
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
if(proxyMethod == V_GET) {
|
||||
// Use GET for FTP via HTTP proxy.
|
||||
getRequest()->setMethod(Request::METHOD_GET);
|
||||
|
@ -123,13 +122,13 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
// Unreachable
|
||||
assert(0);
|
||||
}
|
||||
setupBackupConnection(hostname, addr, port, c);
|
||||
command = c;
|
||||
setupBackupConnection(hostname, addr, port, c.get());
|
||||
return std::move(c);
|
||||
} else {
|
||||
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
|
||||
if(proxyMethod == V_TUNNEL) {
|
||||
// options contains "baseWorkingDir"
|
||||
command = new FtpNegotiationCommand
|
||||
return make_unique<FtpNegotiationCommand>
|
||||
(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
|
@ -146,15 +145,15 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
std::shared_ptr<HttpConnection> hc
|
||||
(new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer));
|
||||
|
||||
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
hc,
|
||||
getDownloadEngine(),
|
||||
pooledSocket);
|
||||
auto c = make_unique<HttpRequestCommand>(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
hc,
|
||||
getDownloadEngine(),
|
||||
pooledSocket);
|
||||
c->setProxyRequest(proxyRequest);
|
||||
command = c;
|
||||
return std::move(c);
|
||||
} else {
|
||||
// Unreachable
|
||||
assert(0);
|
||||
|
@ -174,21 +173,21 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
createSocket();
|
||||
getSocket()->establishConnection(addr, port);
|
||||
getRequest()->setConnectedAddrInfo(hostname, addr, port);
|
||||
ConnectCommand* c = new ConnectCommand(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest, // must be null
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
auto c = make_unique<ConnectCommand>(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest, // must be null
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
std::shared_ptr<FtpNegotiationConnectChain> chain
|
||||
(new FtpNegotiationConnectChain());
|
||||
c->setControlChain(chain);
|
||||
setupBackupConnection(hostname, addr, port, c);
|
||||
command = c;
|
||||
setupBackupConnection(hostname, addr, port, c.get());
|
||||
return std::move(c);
|
||||
} else {
|
||||
// options contains "baseWorkingDir"
|
||||
command = new FtpNegotiationCommand
|
||||
auto command = make_unique<FtpNegotiationCommand>
|
||||
(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
|
@ -198,9 +197,9 @@ Command* FtpInitiateConnectionCommand::createNextCommand
|
|||
FtpNegotiationCommand::SEQ_SEND_CWD_PREP,
|
||||
options);
|
||||
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
|
||||
return std::move(command);
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace aria2 {
|
|||
|
||||
class FtpInitiateConnectionCommand : public InitiateConnectionCommand {
|
||||
protected:
|
||||
virtual Command* createNextCommand
|
||||
virtual std::unique_ptr<Command> createNextCommand
|
||||
(const std::string& hostname, const std::string& addr, uint16_t port,
|
||||
const std::vector<std::string>& resolvedAddresses,
|
||||
const std::shared_ptr<Request>& proxyRequest);
|
||||
|
|
|
@ -110,8 +110,7 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
if(sequence_ == SEQ_RETRY) {
|
||||
return prepareForRetry(0);
|
||||
} else if(sequence_ == SEQ_NEGOTIATION_COMPLETED) {
|
||||
FtpDownloadCommand* command =
|
||||
new FtpDownloadCommand
|
||||
auto command = make_unique<FtpDownloadCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(), ftp_,
|
||||
getDownloadEngine(), dataSocket_, getSocket());
|
||||
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
||||
|
@ -121,8 +120,8 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
getFileEntry()->removeURIWhoseHostnameIs(getRequest()->getHost());
|
||||
}
|
||||
getRequestGroup()->getURISelector()->tuneDownloadCommand
|
||||
(getFileEntry()->getRemainingUris(), command);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
(getFileEntry()->getRemainingUris(), command.get());
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return true;
|
||||
} else if(sequence_ == SEQ_HEAD_OK ||
|
||||
sequence_ == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
|
||||
|
@ -137,7 +136,7 @@ bool FtpNegotiationCommand::executeInternal() {
|
|||
} else if(sequence_ == SEQ_EXIT) {
|
||||
return true;
|
||||
} else {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -473,7 +472,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(int64_t totalLength)
|
|||
poolConnection();
|
||||
return false;
|
||||
}
|
||||
checkIntegrityEntry->pushNextCommand(this);
|
||||
checkIntegrityEntry->pushNextCommand(std::unique_ptr<Command>(this));
|
||||
// We have to make sure that command that has Request object must
|
||||
// have segment after PieceStorage is initialized. See
|
||||
// AbstractCommand::execute()
|
||||
|
|
|
@ -47,7 +47,7 @@ struct FtpNegotiationConnectChain : public ControlChain<ConnectCommand*> {
|
|||
virtual ~FtpNegotiationConnectChain() {}
|
||||
virtual int run(ConnectCommand* t, DownloadEngine* e)
|
||||
{
|
||||
FtpNegotiationCommand* c = new FtpNegotiationCommand
|
||||
auto c = make_unique<FtpNegotiationCommand>
|
||||
(t->getCuid(),
|
||||
t->getRequest(),
|
||||
t->getFileEntry(),
|
||||
|
@ -56,7 +56,7 @@ struct FtpNegotiationConnectChain : public ControlChain<ConnectCommand*> {
|
|||
t->getSocket());
|
||||
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(c);
|
||||
e->addCommand(std::move(c));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "SocketCore.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "SocketRecvBuffer.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -56,9 +57,9 @@ FtpTunnelRequestCommand::FtpTunnelRequestCommand
|
|||
|
||||
FtpTunnelRequestCommand::~FtpTunnelRequestCommand() {}
|
||||
|
||||
Command* FtpTunnelRequestCommand::getNextCommand()
|
||||
std::unique_ptr<Command> FtpTunnelRequestCommand::getNextCommand()
|
||||
{
|
||||
return new FtpTunnelResponseCommand
|
||||
return make_unique<FtpTunnelResponseCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
getHttpConnection(), getDownloadEngine(), getSocket());
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
const std::shared_ptr<SocketCore>& s);
|
||||
virtual ~FtpTunnelRequestCommand();
|
||||
|
||||
virtual Command* getNextCommand();
|
||||
virtual std::unique_ptr<Command> getNextCommand();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -47,7 +47,7 @@ struct FtpTunnelRequestConnectChain : public ControlChain<ConnectCommand*> {
|
|||
virtual ~FtpTunnelRequestConnectChain() {}
|
||||
virtual int run(ConnectCommand* t, DownloadEngine* e)
|
||||
{
|
||||
FtpTunnelRequestCommand* c = new FtpTunnelRequestCommand
|
||||
auto c = make_unique<FtpTunnelRequestCommand>
|
||||
(t->getCuid(),
|
||||
t->getRequest(),
|
||||
t->getFileEntry(),
|
||||
|
@ -57,7 +57,7 @@ struct FtpTunnelRequestConnectChain : public ControlChain<ConnectCommand*> {
|
|||
t->getSocket());
|
||||
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(c);
|
||||
e->addCommand(std::move(c));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -57,11 +57,12 @@ FtpTunnelResponseCommand::FtpTunnelResponseCommand
|
|||
|
||||
FtpTunnelResponseCommand::~FtpTunnelResponseCommand() {}
|
||||
|
||||
Command* FtpTunnelResponseCommand::getNextCommand()
|
||||
std::unique_ptr<Command> FtpTunnelResponseCommand::getNextCommand()
|
||||
{
|
||||
return new FtpNegotiationCommand(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), getDownloadEngine(),
|
||||
getSocket());
|
||||
return make_unique<FtpNegotiationCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), getDownloadEngine(),
|
||||
getSocket());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
const std::shared_ptr<SocketCore>& s);
|
||||
virtual ~FtpTunnelResponseCommand();
|
||||
|
||||
virtual Command* getNextCommand();
|
||||
virtual std::unique_ptr<Command> getNextCommand();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -75,16 +75,16 @@ HttpDownloadCommand::~HttpDownloadCommand() {}
|
|||
bool HttpDownloadCommand::prepareForNextSegment() {
|
||||
bool downloadFinished = getRequestGroup()->downloadFinished();
|
||||
if(getRequest()->isPipeliningEnabled() && !downloadFinished) {
|
||||
HttpRequestCommand* command =
|
||||
new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), httpConnection_,
|
||||
getDownloadEngine(), getSocket());
|
||||
auto command = make_unique<HttpRequestCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), httpConnection_,
|
||||
getDownloadEngine(), getSocket());
|
||||
// Set proxy request here. aria2 sends the HTTP request specialized for
|
||||
// proxy.
|
||||
if(resolveProxyMethod(getRequest()->getProtocol()) == V_GET) {
|
||||
command->setProxyRequest(createProxyRequest());
|
||||
}
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return true;
|
||||
} else {
|
||||
const std::string& streamFilterName = getStreamFilter()->getName();
|
||||
|
|
|
@ -69,12 +69,11 @@ HttpInitiateConnectionCommand::HttpInitiateConnectionCommand
|
|||
|
||||
HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {}
|
||||
|
||||
Command* HttpInitiateConnectionCommand::createNextCommand
|
||||
std::unique_ptr<Command> HttpInitiateConnectionCommand::createNextCommand
|
||||
(const std::string& hostname, const std::string& addr, uint16_t port,
|
||||
const std::vector<std::string>& resolvedAddresses,
|
||||
const std::shared_ptr<Request>& proxyRequest)
|
||||
{
|
||||
Command* command;
|
||||
if(proxyRequest) {
|
||||
std::shared_ptr<SocketCore> pooledSocket =
|
||||
getDownloadEngine()->popPooledSocket
|
||||
|
@ -88,13 +87,13 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
getSocket()->establishConnection(addr, port);
|
||||
|
||||
getRequest()->setConnectedAddrInfo(hostname, addr, port);
|
||||
ConnectCommand* c = new ConnectCommand(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest,
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
auto c = make_unique<ConnectCommand>(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest,
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
if(proxyMethod == V_TUNNEL) {
|
||||
std::shared_ptr<HttpProxyRequestConnectChain> chain
|
||||
(new HttpProxyRequestConnectChain());
|
||||
|
@ -107,25 +106,25 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
// Unreachable
|
||||
assert(0);
|
||||
}
|
||||
setupBackupConnection(hostname, addr, port, c);
|
||||
command = c;
|
||||
setupBackupConnection(hostname, addr, port, c.get());
|
||||
return std::move(c);
|
||||
} else {
|
||||
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
|
||||
std::shared_ptr<SocketRecvBuffer> socketRecvBuffer
|
||||
(new SocketRecvBuffer(pooledSocket));
|
||||
std::shared_ptr<HttpConnection> httpConnection
|
||||
(new HttpConnection(getCuid(), pooledSocket, socketRecvBuffer));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection,
|
||||
getDownloadEngine(),
|
||||
pooledSocket);
|
||||
auto c = make_unique<HttpRequestCommand>(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection,
|
||||
getDownloadEngine(),
|
||||
pooledSocket);
|
||||
if(proxyMethod == V_GET) {
|
||||
c->setProxyRequest(proxyRequest);
|
||||
}
|
||||
command = c;
|
||||
return std::move(c);
|
||||
}
|
||||
} else {
|
||||
std::shared_ptr<SocketCore> pooledSocket =
|
||||
|
@ -138,18 +137,18 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
getSocket()->establishConnection(addr, port);
|
||||
|
||||
getRequest()->setConnectedAddrInfo(hostname, addr, port);
|
||||
ConnectCommand* c = new ConnectCommand(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest, // must be null
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
auto c = make_unique<ConnectCommand>(getCuid(),
|
||||
getRequest(),
|
||||
proxyRequest, // must be null
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
std::shared_ptr<HttpRequestConnectChain> chain
|
||||
(new HttpRequestConnectChain());
|
||||
c->setControlChain(chain);
|
||||
setupBackupConnection(hostname, addr, port, c);
|
||||
command = c;
|
||||
setupBackupConnection(hostname, addr, port, c.get());
|
||||
return std::move(c);
|
||||
} else {
|
||||
setSocket(pooledSocket);
|
||||
setConnectedAddrInfo(getRequest(), hostname, pooledSocket);
|
||||
|
@ -158,16 +157,15 @@ Command* HttpInitiateConnectionCommand::createNextCommand
|
|||
(new SocketRecvBuffer(getSocket()));
|
||||
std::shared_ptr<HttpConnection> httpConnection
|
||||
(new HttpConnection(getCuid(), getSocket(), socketRecvBuffer));
|
||||
command = new HttpRequestCommand(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection,
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
return make_unique<HttpRequestCommand>(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection,
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
}
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace aria2 {
|
|||
// calling execute() returns true.
|
||||
class HttpInitiateConnectionCommand : public InitiateConnectionCommand {
|
||||
protected:
|
||||
virtual Command* createNextCommand
|
||||
virtual std::unique_ptr<Command> createNextCommand
|
||||
(const std::string& hostname, const std::string& addr, uint16_t port,
|
||||
const std::vector<std::string>& resolvedAddresses,
|
||||
const std::shared_ptr<Request>& proxyRequest);
|
||||
|
|
|
@ -80,15 +80,14 @@ bool HttpListenCommand::execute()
|
|||
A2_LOG_INFO(fmt("RPC: Accepted the connection from %s:%u.",
|
||||
peerInfo.first.c_str(), peerInfo.second));
|
||||
|
||||
HttpServerCommand* c =
|
||||
new HttpServerCommand(e_->newCUID(), e_, socket, secure_);
|
||||
e_->setNoWait(true);
|
||||
e_->addCommand(c);
|
||||
e_->addCommand(make_unique<HttpServerCommand>
|
||||
(e_->newCUID(), e_, socket, secure_));
|
||||
}
|
||||
} catch(RecoverableException& e) {
|
||||
A2_LOG_DEBUG_EX(fmt(MSG_ACCEPT_FAILURE, getCuid()), e);
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "Request.h"
|
||||
#include "SocketCore.h"
|
||||
#include "SocketRecvBuffer.h"
|
||||
#include "a2functional.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -55,9 +56,9 @@ HttpProxyRequestCommand::HttpProxyRequestCommand
|
|||
|
||||
HttpProxyRequestCommand::~HttpProxyRequestCommand() {}
|
||||
|
||||
Command* HttpProxyRequestCommand::getNextCommand()
|
||||
std::unique_ptr<Command> HttpProxyRequestCommand::getNextCommand()
|
||||
{
|
||||
return new HttpProxyResponseCommand
|
||||
return make_unique<HttpProxyResponseCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
getHttpConnection(), getDownloadEngine(), getSocket());
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
const std::shared_ptr<SocketCore>& s);
|
||||
virtual ~HttpProxyRequestCommand();
|
||||
|
||||
virtual Command* getNextCommand();
|
||||
virtual std::unique_ptr<Command> getNextCommand();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -47,7 +47,7 @@ struct HttpProxyRequestConnectChain : public ControlChain<ConnectCommand*> {
|
|||
virtual ~HttpProxyRequestConnectChain() {}
|
||||
virtual int run(ConnectCommand* t, DownloadEngine* e)
|
||||
{
|
||||
HttpProxyRequestCommand* c = new HttpProxyRequestCommand
|
||||
auto c = make_unique<HttpProxyRequestCommand>
|
||||
(t->getCuid(),
|
||||
t->getRequest(),
|
||||
t->getFileEntry(),
|
||||
|
@ -57,7 +57,7 @@ struct HttpProxyRequestConnectChain : public ControlChain<ConnectCommand*> {
|
|||
t->getSocket());
|
||||
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(c);
|
||||
e->addCommand(std::move(c));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -57,11 +57,12 @@ HttpProxyResponseCommand::HttpProxyResponseCommand
|
|||
|
||||
HttpProxyResponseCommand::~HttpProxyResponseCommand() {}
|
||||
|
||||
Command* HttpProxyResponseCommand::getNextCommand()
|
||||
std::unique_ptr<Command> HttpProxyResponseCommand::getNextCommand()
|
||||
{
|
||||
return new HttpRequestCommand(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), getHttpConnection(),
|
||||
getDownloadEngine(), getSocket());
|
||||
return make_unique<HttpRequestCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(), getHttpConnection(),
|
||||
getDownloadEngine(), getSocket());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
const std::shared_ptr<SocketCore>& s);
|
||||
virtual ~HttpProxyResponseCommand();
|
||||
|
||||
virtual Command* getNextCommand();
|
||||
virtual std::unique_ptr<Command> getNextCommand();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -130,7 +130,7 @@ bool HttpRequestCommand::executeInternal() {
|
|||
if(!getSocket()->tlsConnect(getRequest()->getHost())) {
|
||||
setReadCheckSocketIf(getSocket(), getSocket()->wantRead());
|
||||
setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -207,19 +207,19 @@ bool HttpRequestCommand::executeInternal() {
|
|||
httpConnection_->sendPendingData();
|
||||
}
|
||||
if(httpConnection_->sendBufferIsEmpty()) {
|
||||
Command* command = new HttpResponseCommand(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection_,
|
||||
getDownloadEngine(),
|
||||
getSocket());
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(make_unique<HttpResponseCommand>
|
||||
(getCuid(),
|
||||
getRequest(),
|
||||
getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpConnection_,
|
||||
getDownloadEngine(),
|
||||
getSocket()));
|
||||
return true;
|
||||
} else {
|
||||
setReadCheckSocketIf(getSocket(), getSocket()->wantRead());
|
||||
setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,17 +53,17 @@ struct HttpRequestConnectChain : public ControlChain<ConnectCommand*> {
|
|||
(new SocketRecvBuffer(t->getSocket()));
|
||||
std::shared_ptr<HttpConnection> httpConnection
|
||||
(new HttpConnection(t->getCuid(), t->getSocket(), socketRecvBuffer));
|
||||
HttpRequestCommand* c = new HttpRequestCommand(t->getCuid(),
|
||||
t->getRequest(),
|
||||
t->getFileEntry(),
|
||||
t->getRequestGroup(),
|
||||
httpConnection,
|
||||
e,
|
||||
t->getSocket());
|
||||
auto c = make_unique<HttpRequestCommand>(t->getCuid(),
|
||||
t->getRequest(),
|
||||
t->getFileEntry(),
|
||||
t->getRequestGroup(),
|
||||
httpConnection,
|
||||
e,
|
||||
t->getSocket());
|
||||
c->setProxyRequest(t->getProxyRequest());
|
||||
c->setStatus(Command::STATUS_ONESHOT_REALTIME);
|
||||
e->setNoWait(true);
|
||||
e->addCommand(c);
|
||||
e->addCommand(std::move(c));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -158,7 +158,7 @@ bool HttpResponseCommand::executeInternal()
|
|||
// For socket->wantRead() == true, setReadCheckSocket(socket) is already
|
||||
// done in the constructor.
|
||||
setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
// check HTTP status number
|
||||
|
@ -377,21 +377,17 @@ bool HttpResponseCommand::handleDefaultEncoding
|
|||
// we can't continue to use this socket because server sends all entity
|
||||
// body instead of a segment.
|
||||
// Therefore, we shutdown the socket here if pipelining is enabled.
|
||||
DownloadCommand* command = 0;
|
||||
if(getRequest()->getMethod() == Request::METHOD_GET &&
|
||||
segment && segment->getPositionToWrite() == 0 &&
|
||||
!getRequest()->isPipeliningEnabled()) {
|
||||
command = createHttpDownloadCommand
|
||||
(httpResponse,
|
||||
getTransferEncodingStreamFilter(httpResponse));
|
||||
checkEntry->pushNextCommand
|
||||
(createHttpDownloadCommand
|
||||
(httpResponse,
|
||||
getTransferEncodingStreamFilter(httpResponse)));
|
||||
} else {
|
||||
getSegmentMan()->cancelSegment(getCuid());
|
||||
getFileEntry()->poolRequest(getRequest());
|
||||
}
|
||||
// After command is passed to prepareForNextAction(), it is managed
|
||||
// by CheckIntegrityEntry.
|
||||
checkEntry->pushNextCommand(command);
|
||||
command = 0;
|
||||
|
||||
prepareForNextAction(checkEntry);
|
||||
|
||||
|
@ -505,7 +501,7 @@ bool HttpResponseCommand::skipResponseBody
|
|||
// We don't use Content-Encoding here because this response body is just
|
||||
// thrown away.
|
||||
|
||||
HttpSkipResponseCommand* command = new HttpSkipResponseCommand
|
||||
auto command = make_unique<HttpSkipResponseCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
httpConnection_, httpResponse,
|
||||
getDownloadEngine(), getSocket());
|
||||
|
@ -522,7 +518,7 @@ bool HttpResponseCommand::skipResponseBody
|
|||
getDownloadEngine()->setNoWait(true);
|
||||
}
|
||||
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -544,16 +540,17 @@ bool decideFileAllocation
|
|||
}
|
||||
} // namespace
|
||||
|
||||
HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
|
||||
std::unique_ptr<HttpDownloadCommand>
|
||||
HttpResponseCommand::createHttpDownloadCommand
|
||||
(const std::shared_ptr<HttpResponse>& httpResponse,
|
||||
const std::shared_ptr<StreamFilter>& filter)
|
||||
{
|
||||
|
||||
HttpDownloadCommand* command =
|
||||
new HttpDownloadCommand(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpResponse, httpConnection_,
|
||||
getDownloadEngine(), getSocket());
|
||||
auto command = make_unique<HttpDownloadCommand>
|
||||
(getCuid(), getRequest(), getFileEntry(),
|
||||
getRequestGroup(),
|
||||
httpResponse, httpConnection_,
|
||||
getDownloadEngine(), getSocket());
|
||||
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
||||
command->setLowestDownloadSpeedLimit
|
||||
(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
||||
|
@ -563,9 +560,9 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
|
|||
getRequestGroup()->setFileAllocationEnabled(false);
|
||||
}
|
||||
getRequestGroup()->getURISelector()->tuneDownloadCommand
|
||||
(getFileEntry()->getRemainingUris(), command);
|
||||
(getFileEntry()->getRemainingUris(), command.get());
|
||||
|
||||
return command;
|
||||
return std::move(command);
|
||||
}
|
||||
|
||||
void HttpResponseCommand::poolConnection()
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
bool handleOtherEncoding(const std::shared_ptr<HttpResponse>& httpResponse);
|
||||
bool skipResponseBody(const std::shared_ptr<HttpResponse>& httpResponse);
|
||||
|
||||
HttpDownloadCommand*
|
||||
std::unique_ptr<HttpDownloadCommand>
|
||||
createHttpDownloadCommand
|
||||
(const std::shared_ptr<HttpResponse>& httpResponse,
|
||||
const std::shared_ptr<StreamFilter>& streamFilter);
|
||||
|
|
|
@ -142,9 +142,8 @@ void HttpServerBodyCommand::sendJsonRpcBatchResponse
|
|||
|
||||
void HttpServerBodyCommand::addHttpServerResponseCommand()
|
||||
{
|
||||
Command* command =
|
||||
new HttpServerResponseCommand(getCuid(), httpServer_, e_, socket_);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(make_unique<HttpServerResponseCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
e_->setNoWait(true);
|
||||
}
|
||||
|
||||
|
@ -309,7 +308,7 @@ bool HttpServerBodyCommand::execute()
|
|||
}
|
||||
} else {
|
||||
updateWriteCheck();
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@ -317,7 +316,7 @@ bool HttpServerBodyCommand::execute()
|
|||
A2_LOG_INFO("HTTP request body timeout.");
|
||||
return true;
|
||||
} else {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ bool HttpServerCommand::execute()
|
|||
// finished.
|
||||
if(!socket_->tlsAccept()) {
|
||||
updateWriteCheck();
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ bool HttpServerCommand::execute()
|
|||
header = httpServer_->receiveRequest();
|
||||
if(!header) {
|
||||
updateWriteCheck();
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
// CORS preflight request uses OPTIONS method. It is not
|
||||
|
@ -204,9 +204,8 @@ bool HttpServerCommand::execute()
|
|||
httpServer_->disableKeepAlive();
|
||||
httpServer_->feedResponse
|
||||
(401, "WWW-Authenticate: Basic realm=\"aria2\"\r\n");
|
||||
Command* command =
|
||||
new HttpServerResponseCommand(getCuid(), httpServer_, e_, socket_);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(make_unique<HttpServerResponseCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
e_->setNoWait(true);
|
||||
return true;
|
||||
}
|
||||
|
@ -214,7 +213,6 @@ bool HttpServerCommand::execute()
|
|||
header->fieldContains(HttpHeader::CONNECTION, "upgrade")) {
|
||||
#ifdef ENABLE_WEBSOCKET
|
||||
int status = websocketHandshake(header);
|
||||
Command* command;
|
||||
if(status == 101) {
|
||||
std::string serverKey =
|
||||
createWebSocketServerKey
|
||||
|
@ -222,26 +220,23 @@ bool HttpServerCommand::execute()
|
|||
httpServer_->feedUpgradeResponse("websocket",
|
||||
fmt("Sec-WebSocket-Accept: %s\r\n",
|
||||
serverKey.c_str()));
|
||||
command = new rpc::WebSocketResponseCommand(getCuid(), httpServer_,
|
||||
e_, socket_);
|
||||
e_->addCommand(make_unique<rpc::WebSocketResponseCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
} else {
|
||||
if(status == 426) {
|
||||
httpServer_->feedResponse(426, "Sec-WebSocket-Version: 13\r\n");
|
||||
} else {
|
||||
httpServer_->feedResponse(status);
|
||||
}
|
||||
command = new HttpServerResponseCommand(getCuid(), httpServer_, e_,
|
||||
socket_);
|
||||
e_->addCommand(make_unique<HttpServerResponseCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
}
|
||||
e_->addCommand(command);
|
||||
e_->setNoWait(true);
|
||||
return true;
|
||||
#else // !ENABLE_WEBSOCKET
|
||||
httpServer_->feedResponse(400);
|
||||
Command* command = new HttpServerResponseCommand(getCuid(),
|
||||
httpServer_, e_,
|
||||
socket_);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(make_unique<HttpServerResponseCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
e_->setNoWait(true);
|
||||
return true;
|
||||
#endif // !ENABLE_WEBSOCKET
|
||||
|
@ -255,9 +250,8 @@ bool HttpServerCommand::execute()
|
|||
httpServer_->getContentLength()));
|
||||
return true;
|
||||
}
|
||||
Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,
|
||||
socket_);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(make_unique<HttpServerBodyCommand>
|
||||
(getCuid(), httpServer_, e_, socket_));
|
||||
e_->setNoWait(true);
|
||||
return true;
|
||||
}
|
||||
|
@ -266,7 +260,7 @@ bool HttpServerCommand::execute()
|
|||
A2_LOG_INFO("HTTP request timeout.");
|
||||
return true;
|
||||
} else {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ void HttpServerResponseCommand::afterSend
|
|||
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Persist connection.",
|
||||
getCuid()));
|
||||
e->addCommand
|
||||
(new HttpServerCommand(getCuid(), httpServer, e,
|
||||
httpServer->getSocket()));
|
||||
(make_unique<HttpServerCommand>(getCuid(), httpServer, e,
|
||||
httpServer->getSocket()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ bool HttpSkipResponseCommand::executeInternal()
|
|||
return processResponse();
|
||||
} else {
|
||||
setWriteCheckSocketIf(getSocket(), getSocket()->wantWrite());
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,13 +87,12 @@ bool InitiateConnectionCommand::executeInternal() {
|
|||
std::vector<std::string> addrs;
|
||||
std::string ipaddr = resolveHostname(addrs, hostname, port);
|
||||
if(ipaddr.empty()) {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Command* command = createNextCommand(hostname, ipaddr, port,
|
||||
addrs, proxyRequest);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(createNextCommand(hostname, ipaddr, port,
|
||||
addrs, proxyRequest));
|
||||
return true;
|
||||
} catch(RecoverableException& ex) {
|
||||
// Catch exception and retry another address.
|
||||
|
@ -106,12 +105,12 @@ bool InitiateConnectionCommand::executeInternal() {
|
|||
A2_LOG_INFO(fmt(MSG_CONNECT_FAILED_AND_RETRY,
|
||||
getCuid(),
|
||||
ipaddr.c_str(), port));
|
||||
Command* command =
|
||||
auto command =
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(getCuid(), getRequest(), getFileEntry(), getRequestGroup(),
|
||||
getDownloadEngine());
|
||||
getDownloadEngine()->setNoWait(true);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return true;
|
||||
}
|
||||
getDownloadEngine()->removeCachedIPAddress(hostname, port);
|
||||
|
@ -149,12 +148,12 @@ InitiateConnectionCommand::createBackupIPv4ConnectCommand
|
|||
eoi = addrs.end(); i != eoi; ++i) {
|
||||
if(inetPton(AF_INET, (*i).c_str(), &buf) == 0) {
|
||||
info.reset(new BackupConnectInfo());
|
||||
BackupIPv4ConnectCommand* command = new BackupIPv4ConnectCommand
|
||||
auto command = make_unique<BackupIPv4ConnectCommand>
|
||||
(getDownloadEngine()->newCUID(), *i, port, info, mainCommand,
|
||||
getRequestGroup(), getDownloadEngine());
|
||||
A2_LOG_INFO(fmt("Issue backup connection command CUID#%" PRId64
|
||||
", addr=%s", command->getCuid(), (*i).c_str()));
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ protected:
|
|||
// use this address this time. resolvedAddresses are all addresses
|
||||
// resolved. proxyRequest is set if we are going to use proxy
|
||||
// server.
|
||||
virtual Command* createNextCommand
|
||||
virtual std::unique_ptr<Command> createNextCommand
|
||||
(const std::string& hostname, const std::string& addr, uint16_t port,
|
||||
const std::vector<std::string>& resolvedAddresses,
|
||||
const std::shared_ptr<Request>& proxyRequest) = 0;
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
Command*
|
||||
std::unique_ptr<Command>
|
||||
InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
||||
(cuid_t cuid,
|
||||
const std::shared_ptr<Request>& req,
|
||||
|
@ -69,16 +69,16 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand
|
|||
req->setPipeliningHint(true);
|
||||
}
|
||||
|
||||
return
|
||||
new HttpInitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e);
|
||||
return make_unique<HttpInitiateConnectionCommand>(cuid, req, fileEntry,
|
||||
requestGroup, e);
|
||||
} else if(req->getProtocol() == "ftp") {
|
||||
if(req->getFile().empty()) {
|
||||
throw DL_ABORT_EX
|
||||
(fmt("FTP URI %s doesn't contain file path.",
|
||||
req->getUri().c_str()));
|
||||
}
|
||||
return
|
||||
new FtpInitiateConnectionCommand(cuid, req, fileEntry, requestGroup, e);
|
||||
return make_unique<FtpInitiateConnectionCommand>(cuid, req, fileEntry,
|
||||
requestGroup, e);
|
||||
} else {
|
||||
// these protocols are not supported yet
|
||||
throw DL_ABORT_EX
|
||||
|
|
|
@ -50,7 +50,7 @@ class FileEntry;
|
|||
|
||||
class InitiateConnectionCommandFactory {
|
||||
public:
|
||||
static Command*
|
||||
static std::unique_ptr<Command>
|
||||
createInitiateConnectionCommand(cuid_t cuid,
|
||||
const std::shared_ptr<Request>& req,
|
||||
const std::shared_ptr<FileEntry>& fileEntry,
|
||||
|
|
|
@ -97,7 +97,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
switch(sequence_) {
|
||||
case INITIATOR_SEND_KEY: {
|
||||
if(!getSocket()->isWritable(0)) {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
setTimeout(getOption()->getAsInt(PREF_BT_TIMEOUT));
|
||||
|
@ -164,15 +164,15 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
peerConnection->presetBuffer(mseHandshake_->getBuffer(),
|
||||
mseHandshake_->getBufferLength());
|
||||
}
|
||||
PeerInteractionCommand* c =
|
||||
new PeerInteractionCommand
|
||||
(getCuid(), requestGroup_, getPeer(), getDownloadEngine(), btRuntime_,
|
||||
pieceStorage_,
|
||||
peerStorage_,
|
||||
getSocket(),
|
||||
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE,
|
||||
peerConnection);
|
||||
getDownloadEngine()->addCommand(c);
|
||||
getDownloadEngine()->addCommand
|
||||
(make_unique<PeerInteractionCommand>
|
||||
(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(), btRuntime_,
|
||||
pieceStorage_,
|
||||
peerStorage_,
|
||||
getSocket(),
|
||||
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE,
|
||||
peerConnection));
|
||||
return true;
|
||||
} else {
|
||||
done = true;
|
||||
|
@ -191,7 +191,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
|
|||
} else {
|
||||
disableWriteCheckSocket();
|
||||
}
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -202,13 +202,11 @@ void InitiatorMSEHandshakeCommand::tryNewPeer()
|
|||
std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
|
||||
// sanity check
|
||||
if(peer) {
|
||||
PeerInitiateConnectionCommand* command;
|
||||
command = new PeerInitiateConnectionCommand(ncuid, requestGroup_, peer,
|
||||
getDownloadEngine(),
|
||||
btRuntime_);
|
||||
auto command = make_unique<PeerInitiateConnectionCommand>
|
||||
(ncuid, requestGroup_, peer, getDownloadEngine(), btRuntime_);
|
||||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,12 +228,12 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
|
|||
// try legacy BitTorrent handshake
|
||||
A2_LOG_INFO(fmt("CUID#%" PRId64 " - Retry using legacy BitTorrent handshake.",
|
||||
getCuid()));
|
||||
PeerInitiateConnectionCommand* command =
|
||||
new PeerInitiateConnectionCommand(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(), btRuntime_, false);
|
||||
auto command = make_unique<PeerInitiateConnectionCommand>
|
||||
(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(), btRuntime_, false);
|
||||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ bool LpdDispatchMessageCommand::execute()
|
|||
tryCount_ = 0;
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ bool LpdReceiveMessageCommand::execute()
|
|||
peer->isLocalPeer()?1:0));
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ SRCS = option_processing.cc\
|
|||
FtpDownloadCommand.cc FtpDownloadCommand.h\
|
||||
FtpTunnelRequestCommand.cc FtpTunnelRequestCommand.h\
|
||||
FtpTunnelResponseCommand.cc FtpTunnelResponseCommand.h\
|
||||
SleepCommand.cc SleepCommand.h\
|
||||
DownloadEngine.cc DownloadEngine.h\
|
||||
Segment.h\
|
||||
GrowSegment.cc GrowSegment.h\
|
||||
|
|
|
@ -95,7 +95,7 @@ bool NameResolveCommand::execute()
|
|||
#ifdef ENABLE_ASYNC_DNS
|
||||
if(e_->getOption()->getAsBool(PREF_ASYNC_DNS)) {
|
||||
if(resolveHostname(res, hostname) == 0) {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
|
|
|
@ -198,4 +198,9 @@ void PeerAbstractCommand::createSocket()
|
|||
socket_.reset(new SocketCore());
|
||||
}
|
||||
|
||||
void PeerAbstractCommand::addCommandSelf()
|
||||
{
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -93,6 +93,7 @@ protected:
|
|||
void disableWriteCheckSocket();
|
||||
void setNoCheck(bool check);
|
||||
void updateKeepAlive();
|
||||
void addCommandSelf();
|
||||
public:
|
||||
PeerAbstractCommand(cuid_t cuid,
|
||||
const std::shared_ptr<Peer>& peer,
|
||||
|
|
|
@ -53,7 +53,7 @@ bool PeerChokeCommand::execute() {
|
|||
if(peerStorage_->chokeRoundIntervalElapsed()) {
|
||||
peerStorage_->executeChoke();
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,20 +84,20 @@ bool PeerInitiateConnectionCommand::executeInternal() {
|
|||
getSocket()->establishConnection(getPeer()->getIPAddress(),
|
||||
getPeer()->getPort(), false);
|
||||
if(mseHandshakeEnabled_) {
|
||||
InitiatorMSEHandshakeCommand* c =
|
||||
new InitiatorMSEHandshakeCommand(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(),
|
||||
btRuntime_, getSocket());
|
||||
auto c = make_unique<InitiatorMSEHandshakeCommand>
|
||||
(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(), btRuntime_, getSocket());
|
||||
c->setPeerStorage(peerStorage_);
|
||||
c->setPieceStorage(pieceStorage_);
|
||||
getDownloadEngine()->addCommand(c);
|
||||
getDownloadEngine()->addCommand(std::move(c));
|
||||
} else {
|
||||
PeerInteractionCommand* command =
|
||||
new PeerInteractionCommand
|
||||
(getCuid(), requestGroup_, getPeer(), getDownloadEngine(),
|
||||
btRuntime_, pieceStorage_, peerStorage_,
|
||||
getSocket(), PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand
|
||||
(make_unique<PeerInteractionCommand>
|
||||
(getCuid(), requestGroup_, getPeer(),
|
||||
getDownloadEngine(),
|
||||
btRuntime_, pieceStorage_, peerStorage_,
|
||||
getSocket(),
|
||||
PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -109,13 +109,11 @@ bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) {
|
|||
std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
|
||||
// sanity check
|
||||
if(peer) {
|
||||
PeerInitiateConnectionCommand* command;
|
||||
command = new PeerInitiateConnectionCommand(ncuid, requestGroup_, peer,
|
||||
getDownloadEngine(),
|
||||
btRuntime_);
|
||||
auto command = make_unique<PeerInitiateConnectionCommand>
|
||||
(ncuid, requestGroup_, peer, getDownloadEngine(), btRuntime_);
|
||||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -384,7 +384,7 @@ bool PeerInteractionCommand::executeInternal() {
|
|||
if(btInteractive_->countPendingMessage() > 0) {
|
||||
setNoCheck(true);
|
||||
}
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -395,13 +395,11 @@ bool PeerInteractionCommand::prepareForNextPeer(time_t wait) {
|
|||
std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
|
||||
// sanity check
|
||||
if(peer) {
|
||||
PeerInitiateConnectionCommand* command;
|
||||
command = new PeerInitiateConnectionCommand(ncuid, requestGroup_, peer,
|
||||
getDownloadEngine(),
|
||||
btRuntime_);
|
||||
auto command = make_unique<PeerInitiateConnectionCommand>
|
||||
(ncuid, requestGroup_, peer, getDownloadEngine(), btRuntime_);
|
||||
command->setPeerStorage(peerStorage_);
|
||||
command->setPieceStorage(pieceStorage_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
getDownloadEngine()->addCommand(std::move(command));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -115,9 +115,8 @@ bool PeerListenCommand::execute() {
|
|||
|
||||
std::shared_ptr<Peer> peer(new Peer(peerInfo.first, peerInfo.second, true));
|
||||
cuid_t cuid = e_->newCUID();
|
||||
Command* command =
|
||||
new ReceiverMSEHandshakeCommand(cuid, peer, e_, peerSocket);
|
||||
e_->addCommand(command);
|
||||
e_->addCommand(make_unique<ReceiverMSEHandshakeCommand>
|
||||
(cuid, peer, e_, peerSocket));
|
||||
A2_LOG_DEBUG(fmt("Accepted the connection from %s:%u.",
|
||||
peer->getIPAddress().c_str(),
|
||||
peer->getPort()));
|
||||
|
@ -129,7 +128,7 @@ bool PeerListenCommand::execute() {
|
|||
ex);
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,8 +142,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
// that the added peer must be checked out.
|
||||
if(peerStorage->addPeer(getPeer()) &&
|
||||
peerStorage->checkoutPeer(getCuid())) {
|
||||
PeerInteractionCommand* command =
|
||||
new PeerInteractionCommand
|
||||
getDownloadEngine()->addCommand(make_unique<PeerInteractionCommand>
|
||||
(getCuid(),
|
||||
downloadContext->getOwnerRequestGroup(),
|
||||
getPeer(),
|
||||
|
@ -153,8 +152,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
peerStorage,
|
||||
getSocket(),
|
||||
PeerInteractionCommand::RECEIVER_WAIT_HANDSHAKE,
|
||||
peerConnection_);
|
||||
getDownloadEngine()->addCommand(command);
|
||||
peerConnection_));
|
||||
A2_LOG_DEBUG(fmt(MSG_INCOMING_PEER_CONNECTION,
|
||||
getCuid(),
|
||||
getPeer()->usedBy()));
|
||||
|
@ -162,7 +160,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
|||
}
|
||||
return true;
|
||||
} else {
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ namespace aria2 {
|
|||
|
||||
PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry
|
||||
(RequestGroup* requestGroup,
|
||||
Command* nextCommand):
|
||||
CheckIntegrityEntry(requestGroup, nextCommand) {}
|
||||
std::unique_ptr<Command> nextCommand):
|
||||
CheckIntegrityEntry(requestGroup, std::move(nextCommand)) {}
|
||||
|
||||
PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
|
||||
|
||||
|
|
|
@ -42,7 +42,9 @@ namespace aria2 {
|
|||
class PieceHashCheckIntegrityEntry : public CheckIntegrityEntry
|
||||
{
|
||||
public:
|
||||
PieceHashCheckIntegrityEntry(RequestGroup* requestGroup, Command* nextCommand = 0);
|
||||
PieceHashCheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~PieceHashCheckIntegrityEntry();
|
||||
|
||||
|
|
|
@ -107,12 +107,12 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
|
|||
(new PeerConnection(getCuid(), getPeer(), getSocket()));
|
||||
peerConnection->presetBuffer(mseHandshake_->getBuffer(),
|
||||
mseHandshake_->getBufferLength());
|
||||
Command* c = new PeerReceiveHandshakeCommand(getCuid(),
|
||||
getPeer(),
|
||||
getDownloadEngine(),
|
||||
getSocket(),
|
||||
peerConnection);
|
||||
getDownloadEngine()->addCommand(c);
|
||||
getDownloadEngine()->addCommand
|
||||
(make_unique<PeerReceiveHandshakeCommand>(getCuid(),
|
||||
getPeer(),
|
||||
getDownloadEngine(),
|
||||
getSocket(),
|
||||
peerConnection));
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
|
@ -200,7 +200,7 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
|
|||
} else {
|
||||
disableWriteCheckSocket();
|
||||
}
|
||||
getDownloadEngine()->addCommand(this);
|
||||
addCommandSelf();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -219,10 +219,9 @@ void ReceiverMSEHandshakeCommand::createCommand()
|
|||
// TODO add mseHandshake_->getInfoHash() to PeerReceiveHandshakeCommand
|
||||
// as a hint. If this info hash and one in BitTorrent Handshake does not
|
||||
// match, then drop connection.
|
||||
Command* c =
|
||||
new PeerReceiveHandshakeCommand(getCuid(), getPeer(), getDownloadEngine(),
|
||||
getSocket(), peerConnection);
|
||||
getDownloadEngine()->addCommand(c);
|
||||
getDownloadEngine()->addCommand(make_unique<PeerReceiveHandshakeCommand>
|
||||
(getCuid(), getPeer(), getDownloadEngine(),
|
||||
getSocket(), peerConnection));
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -277,7 +277,7 @@ std::shared_ptr<CheckIntegrityEntry> RequestGroup::createCheckIntegrityEntry()
|
|||
}
|
||||
|
||||
void RequestGroup::createInitialCommand
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
// Start session timer here. When file size becomes known, it will
|
||||
// be reset again in *FileAllocationEntry, because hash check and
|
||||
|
@ -369,15 +369,11 @@ void RequestGroup::createInitialCommand
|
|||
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
||||
option_->getAsBool(PREF_ENABLE_DHT6))) {
|
||||
if(option_->getAsBool(PREF_ENABLE_DHT)) {
|
||||
std::vector<Command*> dhtCommands;
|
||||
DHTSetup().setup(dhtCommands, e, AF_INET);
|
||||
e->addCommand(dhtCommands);
|
||||
e->addCommand(DHTSetup().setup(e, AF_INET));
|
||||
}
|
||||
if(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
||||
option_->getAsBool(PREF_ENABLE_DHT6)) {
|
||||
std::vector<Command*> dhtCommands;
|
||||
DHTSetup().setup(dhtCommands, e, AF_INET6);
|
||||
e->addCommand(dhtCommands);
|
||||
e->addCommand(DHTSetup().setup(e, AF_INET6));
|
||||
}
|
||||
} else {
|
||||
A2_LOG_NOTICE(_("For BitTorrent Magnet URI, enabling DHT is strongly"
|
||||
|
@ -439,27 +435,23 @@ void RequestGroup::createInitialCommand
|
|||
(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
||||
option_->getAsBool(PREF_ENABLE_DHT6)))) {
|
||||
if(option_->getAsBool(PREF_ENABLE_DHT)) {
|
||||
std::vector<Command*> dhtCommands;
|
||||
DHTSetup().setup(dhtCommands, e, AF_INET);
|
||||
e->addCommand(dhtCommands);
|
||||
e->addCommand(DHTSetup().setup(e, AF_INET));
|
||||
}
|
||||
if(!e->getOption()->getAsBool(PREF_DISABLE_IPV6) &&
|
||||
option_->getAsBool(PREF_ENABLE_DHT6)) {
|
||||
std::vector<Command*> dhtCommands;
|
||||
DHTSetup().setup(dhtCommands, e, AF_INET6);
|
||||
e->addCommand(dhtCommands);
|
||||
e->addCommand(DHTSetup().setup(e, AF_INET6));
|
||||
}
|
||||
const std::vector<std::pair<std::string, uint16_t> >& nodes =
|
||||
torrentAttrs->nodes;
|
||||
// TODO Are nodes in torrent IPv4 only?
|
||||
if(!nodes.empty() && DHTRegistry::isInitialized()) {
|
||||
DHTEntryPointNameResolveCommand* command =
|
||||
new DHTEntryPointNameResolveCommand(e->newCUID(), e, nodes);
|
||||
auto command = make_unique<DHTEntryPointNameResolveCommand>
|
||||
(e->newCUID(), e, nodes);
|
||||
command->setTaskQueue(DHTRegistry::getData().taskQueue);
|
||||
command->setTaskFactory(DHTRegistry::getData().taskFactory);
|
||||
command->setRoutingTable(DHTRegistry::getData().routingTable);
|
||||
command->setLocalNode(DHTRegistry::getData().localNode);
|
||||
e->addCommand(command);
|
||||
e->addCommand(std::move(command));
|
||||
}
|
||||
}
|
||||
std::shared_ptr<CheckIntegrityEntry> entry(new BtCheckIntegrityEntry(this));
|
||||
|
@ -553,7 +545,7 @@ void RequestGroup::createInitialCommand
|
|||
}
|
||||
|
||||
void RequestGroup::processCheckIntegrityEntry
|
||||
(std::vector<Command*>& commands,
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
const std::shared_ptr<CheckIntegrityEntry>& entry,
|
||||
DownloadEngine* e)
|
||||
{
|
||||
|
@ -804,8 +796,9 @@ bool RequestGroup::tryAutoFileRenaming()
|
|||
return false;
|
||||
}
|
||||
|
||||
void RequestGroup::createNextCommandWithAdj(std::vector<Command*>& commands,
|
||||
DownloadEngine* e, int numAdj)
|
||||
void RequestGroup::createNextCommandWithAdj
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e, int numAdj)
|
||||
{
|
||||
int numCommand;
|
||||
if(getTotalLength() == 0) {
|
||||
|
@ -820,8 +813,9 @@ void RequestGroup::createNextCommandWithAdj(std::vector<Command*>& commands,
|
|||
}
|
||||
}
|
||||
|
||||
void RequestGroup::createNextCommand(std::vector<Command*>& commands,
|
||||
DownloadEngine* e)
|
||||
void RequestGroup::createNextCommand
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e)
|
||||
{
|
||||
int numCommand;
|
||||
if(getTotalLength() == 0) {
|
||||
|
@ -844,13 +838,14 @@ void RequestGroup::createNextCommand(std::vector<Command*>& commands,
|
|||
}
|
||||
}
|
||||
|
||||
void RequestGroup::createNextCommand(std::vector<Command*>& commands,
|
||||
DownloadEngine* e,
|
||||
int numCommand)
|
||||
void RequestGroup::createNextCommand
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e,
|
||||
int numCommand)
|
||||
{
|
||||
for(; numCommand > 0; --numCommand) {
|
||||
Command* command = new CreateRequestCommand(e->newCUID(), this, e);
|
||||
commands.push_back(command);
|
||||
commands.push_back(make_unique<CreateRequestCommand>
|
||||
(e->newCUID(), this, e));
|
||||
}
|
||||
if(!commands.empty()) {
|
||||
e->setNoWait(true);
|
||||
|
|
|
@ -215,16 +215,18 @@ public:
|
|||
// Returns first bootstrap commands to initiate a download.
|
||||
// If this is HTTP/FTP download and file size is unknown, only 1 command
|
||||
// (usually, HttpInitiateConnection or FtpInitiateConnection) will be created.
|
||||
void createInitialCommand(std::vector<Command*>& commands,
|
||||
void createInitialCommand(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e);
|
||||
|
||||
void createNextCommandWithAdj(std::vector<Command*>& commands,
|
||||
DownloadEngine* e, int numAdj);
|
||||
void createNextCommandWithAdj
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e, int numAdj);
|
||||
|
||||
void createNextCommand(std::vector<Command*>& commands,
|
||||
void createNextCommand(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e, int numCommand);
|
||||
|
||||
void createNextCommand(std::vector<Command*>& commands, DownloadEngine* e);
|
||||
void createNextCommand(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e);
|
||||
|
||||
bool downloadFinished() const;
|
||||
|
||||
|
@ -383,9 +385,10 @@ public:
|
|||
|
||||
void clearPreDownloadHandler();
|
||||
|
||||
void processCheckIntegrityEntry(std::vector<Command*>& commands,
|
||||
const std::shared_ptr<CheckIntegrityEntry>& entry,
|
||||
DownloadEngine* e);
|
||||
void processCheckIntegrityEntry
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
const std::shared_ptr<CheckIntegrityEntry>& entry,
|
||||
DownloadEngine* e);
|
||||
|
||||
// Initializes pieceStorage_ and segmentMan_. We guarantee that
|
||||
// either both of pieceStorage_ and segmentMan_ are initialized or
|
||||
|
|
|
@ -40,9 +40,9 @@
|
|||
namespace aria2 {
|
||||
|
||||
RequestGroupEntry::RequestGroupEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand):
|
||||
std::unique_ptr<Command> nextCommand):
|
||||
requestGroup_(requestGroup),
|
||||
nextCommand_(nextCommand)
|
||||
nextCommand_(std::move(nextCommand))
|
||||
{
|
||||
requestGroup_->increaseNumCommand();
|
||||
}
|
||||
|
@ -50,20 +50,16 @@ RequestGroupEntry::RequestGroupEntry(RequestGroup* requestGroup,
|
|||
RequestGroupEntry::~RequestGroupEntry()
|
||||
{
|
||||
requestGroup_->decreaseNumCommand();
|
||||
delete nextCommand_;
|
||||
}
|
||||
|
||||
Command* RequestGroupEntry::popNextCommand()
|
||||
std::unique_ptr<Command> RequestGroupEntry::popNextCommand()
|
||||
{
|
||||
Command* temp = nextCommand_;
|
||||
nextCommand_ = 0;
|
||||
return temp;
|
||||
return std::move(nextCommand_);
|
||||
}
|
||||
|
||||
void RequestGroupEntry::pushNextCommand(Command* nextCommand)
|
||||
void RequestGroupEntry::pushNextCommand(std::unique_ptr<Command> nextCommand)
|
||||
{
|
||||
delete nextCommand_;
|
||||
nextCommand_ = nextCommand;
|
||||
nextCommand_ = std::move(nextCommand);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class RequestGroup;
|
||||
|
@ -45,10 +47,11 @@ class Command;
|
|||
class RequestGroupEntry {
|
||||
private:
|
||||
RequestGroup* requestGroup_;
|
||||
Command* nextCommand_;
|
||||
std::unique_ptr<Command> nextCommand_;
|
||||
public:
|
||||
RequestGroupEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand = 0);
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~RequestGroupEntry();
|
||||
|
||||
|
@ -59,12 +62,12 @@ public:
|
|||
|
||||
Command* getNextCommand() const
|
||||
{
|
||||
return nextCommand_;
|
||||
return nextCommand_.get();
|
||||
}
|
||||
|
||||
Command* popNextCommand();
|
||||
std::unique_ptr<Command> popNextCommand();
|
||||
|
||||
void pushNextCommand(Command* nextCommand);
|
||||
void pushNextCommand(std::unique_ptr<Command> nextCommand);
|
||||
|
||||
bool operator==(const RequestGroupEntry& entry) const
|
||||
{
|
||||
|
|
|
@ -438,11 +438,12 @@ void RequestGroupMan::configureRequestGroup
|
|||
}
|
||||
|
||||
namespace {
|
||||
void createInitialCommand(const std::shared_ptr<RequestGroup>& requestGroup,
|
||||
std::vector<Command*>& commands,
|
||||
DownloadEngine* e)
|
||||
std::vector<std::unique_ptr<Command>> createInitialCommand
|
||||
(const std::shared_ptr<RequestGroup>& requestGroup, DownloadEngine* e)
|
||||
{
|
||||
requestGroup->createInitialCommand(commands, e);
|
||||
std::vector<std::unique_ptr<Command>> res;
|
||||
requestGroup->createInitialCommand(res, e);
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -483,24 +484,21 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|||
groupToAdd->dropPieceStorage();
|
||||
configureRequestGroup(groupToAdd);
|
||||
groupToAdd->setRequestGroupMan(this);
|
||||
std::vector<Command*> commands;
|
||||
try {
|
||||
createInitialCommand(groupToAdd, commands, e);
|
||||
auto res = createInitialCommand(groupToAdd, e);
|
||||
++count;
|
||||
if(res.empty()) {
|
||||
requestQueueCheck();
|
||||
} else {
|
||||
e->addCommand(std::move(res));
|
||||
}
|
||||
} catch(RecoverableException& ex) {
|
||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, ex);
|
||||
A2_LOG_DEBUG("Deleting temporal commands.");
|
||||
std::for_each(commands.begin(), commands.end(), Deleter());
|
||||
commands.clear();
|
||||
A2_LOG_DEBUG("Commands deleted");
|
||||
groupToAdd->setLastErrorCode(ex.getErrorCode());
|
||||
// We add groupToAdd to e later in order to it is processed in
|
||||
// removeStoppedGroup().
|
||||
}
|
||||
if(commands.empty()) {
|
||||
requestQueueCheck();
|
||||
} else {
|
||||
e->addCommand(commands);
|
||||
}
|
||||
groupToAdd->setState(RequestGroup::STATE_ACTIVE);
|
||||
requestGroups_.push_back(groupToAdd->getGID(), groupToAdd);
|
||||
|
|
|
@ -1312,9 +1312,9 @@ std::shared_ptr<ValueBase> ChangeUriRpcMethod::process
|
|||
}
|
||||
}
|
||||
if(addcount && group->getPieceStorage()) {
|
||||
std::vector<Command*> commands;
|
||||
std::vector<std::unique_ptr<Command>> commands;
|
||||
group->createNextCommand(commands, e);
|
||||
e->addCommand(commands);
|
||||
e->addCommand(std::move(commands));
|
||||
group->getSegmentMan()->recognizeSegmentFor(s);
|
||||
}
|
||||
std::shared_ptr<List> res = List::g();
|
||||
|
@ -1329,7 +1329,8 @@ std::shared_ptr<ValueBase> goingShutdown
|
|||
{
|
||||
// Schedule shutdown after 3seconds to give time to client to
|
||||
// receive RPC response.
|
||||
e->addRoutineCommand(new TimedHaltCommand(e->newCUID(), e, 3, forceHalt));
|
||||
e->addRoutineCommand(make_unique<TimedHaltCommand>
|
||||
(e->newCUID(), e, 3, forceHalt));
|
||||
A2_LOG_INFO("Scheduled shutdown in 3 seconds.");
|
||||
return VLB_OK;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ bool SeedCheckCommand::execute() {
|
|||
btRuntime_->setHalt(true);
|
||||
}
|
||||
}
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,12 +78,13 @@ public:
|
|||
e_->setNoWait(true);
|
||||
}
|
||||
|
||||
e_->addRoutineCommand(this);
|
||||
e_->addRoutineCommand(std::unique_ptr<Command>(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Command* createCommand(const std::shared_ptr<T>& entry) = 0;
|
||||
virtual std::unique_ptr<Command> createCommand
|
||||
(const std::shared_ptr<T>& entry) = 0;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "SleepCommand.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "DownloadEngine.h"
|
||||
#include "wallclock.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
SleepCommand::SleepCommand(cuid_t cuid, DownloadEngine* e,
|
||||
RequestGroup* requestGroup,
|
||||
Command* nextCommand, time_t wait):
|
||||
Command(cuid), engine_(e), requestGroup_(requestGroup),
|
||||
nextCommand_(nextCommand), wait_(wait), checkPoint_(global::wallclock()) {}
|
||||
|
||||
SleepCommand::~SleepCommand() {
|
||||
delete nextCommand_;
|
||||
}
|
||||
|
||||
bool SleepCommand::execute() {
|
||||
if(requestGroup_->downloadFinished() || requestGroup_->isHaltRequested()) {
|
||||
return true;
|
||||
} else if(checkPoint_.differenceInMillis(global::wallclock())+A2_DELTA_MILLIS
|
||||
>= wait_*1000) {
|
||||
engine_->addCommand(nextCommand_);
|
||||
nextCommand_ = 0;
|
||||
engine_->setNoWait(true);
|
||||
return true;
|
||||
} else {
|
||||
engine_->addCommand(this);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,62 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef D_SLEEP_COMMAND_H
|
||||
#define D_SLEEP_COMMAND_H
|
||||
|
||||
#include "Command.h"
|
||||
#include "TimerA2.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class DownloadEngine;
|
||||
class RequestGroup;
|
||||
|
||||
class SleepCommand:public Command {
|
||||
private:
|
||||
DownloadEngine* engine_;
|
||||
RequestGroup* requestGroup_;
|
||||
Command* nextCommand_;
|
||||
time_t wait_;
|
||||
Timer checkPoint_;
|
||||
public:
|
||||
SleepCommand(cuid_t cuid, DownloadEngine* e, RequestGroup* requestGroup,
|
||||
Command* nextCommand, time_t wait);
|
||||
virtual ~SleepCommand();
|
||||
bool execute();
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // D_SLEEP_COMMAND_H
|
|
@ -42,15 +42,15 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
StreamCheckIntegrityEntry::StreamCheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand):
|
||||
PieceHashCheckIntegrityEntry(requestGroup, nextCommand)
|
||||
StreamCheckIntegrityEntry::StreamCheckIntegrityEntry
|
||||
(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand):
|
||||
PieceHashCheckIntegrityEntry(requestGroup, std::move(nextCommand))
|
||||
{}
|
||||
|
||||
StreamCheckIntegrityEntry::~StreamCheckIntegrityEntry() {}
|
||||
|
||||
void StreamCheckIntegrityEntry::onDownloadIncomplete
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{
|
||||
const std::shared_ptr<PieceStorage>& ps = getRequestGroup()->getPieceStorage();
|
||||
ps->onDownloadIncomplete();
|
||||
|
@ -63,7 +63,7 @@ void StreamCheckIntegrityEntry::onDownloadIncomplete
|
|||
}
|
||||
|
||||
void StreamCheckIntegrityEntry::onDownloadFinished
|
||||
(std::vector<Command*>& commands, DownloadEngine* e)
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e)
|
||||
{}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -43,15 +43,16 @@ class StreamCheckIntegrityEntry:public PieceHashCheckIntegrityEntry
|
|||
{
|
||||
public:
|
||||
StreamCheckIntegrityEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand = 0);
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~StreamCheckIntegrityEntry();
|
||||
|
||||
virtual void onDownloadFinished(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadFinished
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e);
|
||||
|
||||
virtual void onDownloadIncomplete(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void onDownloadIncomplete
|
||||
(std::vector<std::unique_ptr<Command>>& commands, DownloadEngine* e);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -49,15 +49,15 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
StreamFileAllocationEntry::StreamFileAllocationEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand):
|
||||
FileAllocationEntry(requestGroup, nextCommand)
|
||||
StreamFileAllocationEntry::StreamFileAllocationEntry
|
||||
(RequestGroup* requestGroup, std::unique_ptr<Command> nextCommand):
|
||||
FileAllocationEntry(requestGroup, std::move(nextCommand))
|
||||
{}
|
||||
|
||||
StreamFileAllocationEntry::~StreamFileAllocationEntry() {}
|
||||
|
||||
void StreamFileAllocationEntry::prepareForNextAction
|
||||
(std::vector<Command*>& commands,
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e)
|
||||
{
|
||||
// For DownloadContext::resetDownloadStartTime(), see also
|
||||
|
|
|
@ -42,12 +42,14 @@ namespace aria2 {
|
|||
class StreamFileAllocationEntry : public FileAllocationEntry {
|
||||
public:
|
||||
StreamFileAllocationEntry(RequestGroup* requestGroup,
|
||||
Command* nextCommand = 0);
|
||||
std::unique_ptr<Command> nextCommand =
|
||||
std::unique_ptr<Command>());
|
||||
|
||||
virtual ~StreamFileAllocationEntry();
|
||||
|
||||
virtual void prepareForNextAction(std::vector<Command*>& commands,
|
||||
DownloadEngine* e);
|
||||
virtual void prepareForNextAction
|
||||
(std::vector<std::unique_ptr<Command>>& commands,
|
||||
DownloadEngine* e);
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -64,9 +64,9 @@ bool TimeBasedCommand::execute()
|
|||
return true;
|
||||
}
|
||||
if(routineCommand_) {
|
||||
e_->addRoutineCommand(this);
|
||||
e_->addRoutineCommand(std::unique_ptr<Command>(this));
|
||||
} else {
|
||||
e_->addCommand(this);
|
||||
e_->addCommand(std::unique_ptr<Command>(this));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue