mirror of https://github.com/aria2/aria2
TrackerWatcherCommand: Use std::unique_ptr for trackerRequest_
parent
5378ed8c43
commit
3c66c18489
|
@ -70,8 +70,8 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
HTTPAnnRequest::HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg)
|
HTTPAnnRequest::HTTPAnnRequest(std::unique_ptr<RequestGroup> rg)
|
||||||
: rg_(rg)
|
: rg_{std::move(rg)}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
HTTPAnnRequest::~HTTPAnnRequest()
|
HTTPAnnRequest::~HTTPAnnRequest()
|
||||||
|
@ -275,10 +275,9 @@ void TrackerWatcherCommand::addConnection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest>
|
std::unique_ptr<AnnRequest>
|
||||||
TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
||||||
{
|
{
|
||||||
std::shared_ptr<AnnRequest> treq;
|
|
||||||
while(!btAnnounce_->isAllAnnounceFailed() &&
|
while(!btAnnounce_->isAllAnnounceFailed() &&
|
||||||
btAnnounce_->isAnnounceReady()) {
|
btAnnounce_->isAnnounceReady()) {
|
||||||
std::string uri = btAnnounce_->getAnnounceUrl();
|
std::string uri = btAnnounce_->getAnnounceUrl();
|
||||||
|
@ -287,6 +286,7 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
||||||
if(uri_split(&res, uri.c_str()) == 0) {
|
if(uri_split(&res, uri.c_str()) == 0) {
|
||||||
// Without UDP tracker support, send it to normal tracker flow
|
// Without UDP tracker support, send it to normal tracker flow
|
||||||
// and make it fail.
|
// and make it fail.
|
||||||
|
std::unique_ptr<AnnRequest> treq;
|
||||||
if(udpTrackerClient_ &&
|
if(udpTrackerClient_ &&
|
||||||
uri::getFieldString(res, USR_SCHEME, uri.c_str()) == "udp") {
|
uri::getFieldString(res, USR_SCHEME, uri.c_str()) == "udp") {
|
||||||
uint16_t localPort;
|
uint16_t localPort;
|
||||||
|
@ -298,7 +298,7 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
||||||
treq = createHTTPAnnRequest(btAnnounce_->getAnnounceUrl());
|
treq = createHTTPAnnRequest(btAnnounce_->getAnnounceUrl());
|
||||||
}
|
}
|
||||||
btAnnounce_->announceStart(); // inside it, trackers++.
|
btAnnounce_->announceStart(); // inside it, trackers++.
|
||||||
break;
|
return treq;
|
||||||
} else {
|
} else {
|
||||||
btAnnounce_->announceFailure();
|
btAnnounce_->announceFailure();
|
||||||
}
|
}
|
||||||
|
@ -306,17 +306,16 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
||||||
if(btAnnounce_->isAllAnnounceFailed()) {
|
if(btAnnounce_->isAllAnnounceFailed()) {
|
||||||
btAnnounce_->resetAnnounce();
|
btAnnounce_->resetAnnounce();
|
||||||
}
|
}
|
||||||
return treq;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest>
|
std::unique_ptr<AnnRequest>
|
||||||
TrackerWatcherCommand::createUDPAnnRequest(const std::string& host,
|
TrackerWatcherCommand::createUDPAnnRequest(const std::string& host,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
uint16_t localPort)
|
uint16_t localPort)
|
||||||
{
|
{
|
||||||
std::shared_ptr<UDPTrackerRequest> req =
|
return make_unique<UDPAnnRequest>
|
||||||
btAnnounce_->createUDPTrackerRequest(host, port, localPort);
|
(btAnnounce_->createUDPTrackerRequest(host, port, localPort));
|
||||||
return std::shared_ptr<AnnRequest>(new UDPAnnRequest(req));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -338,13 +337,13 @@ bool backupTrackerIsAvailable
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest>
|
std::unique_ptr<AnnRequest>
|
||||||
TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
|
TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
|
||||||
{
|
{
|
||||||
std::vector<std::string> uris;
|
std::vector<std::string> uris;
|
||||||
uris.push_back(uri);
|
uris.push_back(uri);
|
||||||
std::shared_ptr<Option> option = util::copy(getOption());
|
auto option = util::copy(getOption());
|
||||||
std::shared_ptr<RequestGroup> rg(new RequestGroup(GroupId::create(), option));
|
auto rg = make_unique<RequestGroup>(GroupId::create(), option);
|
||||||
if(backupTrackerIsAvailable(requestGroup_->getDownloadContext())) {
|
if(backupTrackerIsAvailable(requestGroup_->getDownloadContext())) {
|
||||||
A2_LOG_DEBUG("This is multi-tracker announce.");
|
A2_LOG_DEBUG("This is multi-tracker announce.");
|
||||||
} else {
|
} else {
|
||||||
|
@ -363,13 +362,13 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
|
||||||
option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT));
|
option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT));
|
||||||
option->put(PREF_REUSE_URI, A2_V_FALSE);
|
option->put(PREF_REUSE_URI, A2_V_FALSE);
|
||||||
option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE);
|
option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE);
|
||||||
std::shared_ptr<DownloadContext> dctx
|
auto dctx = std::make_shared<DownloadContext>
|
||||||
(new DownloadContext(option->getAsInt(PREF_PIECE_LENGTH),
|
(option->getAsInt(PREF_PIECE_LENGTH),
|
||||||
0,
|
0,
|
||||||
"[tracker.announce]"));
|
"[tracker.announce]");
|
||||||
dctx->getFileEntries().front()->setUris(uris);
|
dctx->getFileEntries().front()->setUris(uris);
|
||||||
rg->setDownloadContext(dctx);
|
rg->setDownloadContext(dctx);
|
||||||
std::shared_ptr<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory());
|
auto dwf = std::make_shared<ByteArrayDiskWriterFactory>();
|
||||||
rg->setDiskWriterFactory(dwf);
|
rg->setDiskWriterFactory(dwf);
|
||||||
rg->setFileAllocationEnabled(false);
|
rg->setFileAllocationEnabled(false);
|
||||||
rg->setPreLocalFileCheckEnabled(false);
|
rg->setPreLocalFileCheckEnabled(false);
|
||||||
|
@ -380,7 +379,7 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
|
||||||
dctx->setAcceptMetalink(false);
|
dctx->setAcceptMetalink(false);
|
||||||
A2_LOG_INFO(fmt("Creating tracker request group GID#%s",
|
A2_LOG_INFO(fmt("Creating tracker request group GID#%s",
|
||||||
GroupId::toHex(rg->getGID()).c_str()));
|
GroupId::toHex(rg->getGID()).c_str()));
|
||||||
return std::shared_ptr<AnnRequest>(new HTTPAnnRequest(rg));
|
return make_unique<HTTPAnnRequest>(std::move(rg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerWatcherCommand::setBtRuntime
|
void TrackerWatcherCommand::setBtRuntime
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
|
|
||||||
class HTTPAnnRequest:public AnnRequest {
|
class HTTPAnnRequest:public AnnRequest {
|
||||||
public:
|
public:
|
||||||
HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg);
|
HTTPAnnRequest(std::unique_ptr<RequestGroup> rg);
|
||||||
virtual ~HTTPAnnRequest();
|
virtual ~HTTPAnnRequest();
|
||||||
virtual bool stopped() const CXX11_OVERRIDE;
|
virtual bool stopped() const CXX11_OVERRIDE;
|
||||||
virtual bool success() const CXX11_OVERRIDE;
|
virtual bool success() const CXX11_OVERRIDE;
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce)
|
virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce)
|
||||||
CXX11_OVERRIDE;
|
CXX11_OVERRIDE;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<RequestGroup> rg_;
|
std::unique_ptr<RequestGroup> rg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UDPAnnRequest:public AnnRequest {
|
class UDPAnnRequest:public AnnRequest {
|
||||||
|
@ -113,16 +113,16 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<BtAnnounce> btAnnounce_;
|
std::shared_ptr<BtAnnounce> btAnnounce_;
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest> trackerRequest_;
|
std::unique_ptr<AnnRequest> trackerRequest_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a command for announce request. Returns 0 if no announce request
|
* Returns a command for announce request. Returns 0 if no announce request
|
||||||
* is needed.
|
* is needed.
|
||||||
*/
|
*/
|
||||||
std::shared_ptr<AnnRequest>
|
std::unique_ptr<AnnRequest>
|
||||||
createHTTPAnnRequest(const std::string& uri);
|
createHTTPAnnRequest(const std::string& uri);
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest>
|
std::unique_ptr<AnnRequest>
|
||||||
createUDPAnnRequest(const std::string& host, uint16_t port,
|
createUDPAnnRequest(const std::string& host, uint16_t port,
|
||||||
uint16_t localPort);
|
uint16_t localPort);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ public:
|
||||||
|
|
||||||
virtual ~TrackerWatcherCommand();
|
virtual ~TrackerWatcherCommand();
|
||||||
|
|
||||||
std::shared_ptr<AnnRequest> createAnnounce(DownloadEngine* e);
|
std::unique_ptr<AnnRequest> createAnnounce(DownloadEngine* e);
|
||||||
|
|
||||||
virtual bool execute() CXX11_OVERRIDE;
|
virtual bool execute() CXX11_OVERRIDE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue