diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 303b0c64b..0cb057a44 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -70,8 +70,8 @@ namespace aria2 { -HTTPAnnRequest::HTTPAnnRequest(const std::shared_ptr& rg) - : rg_(rg) +HTTPAnnRequest::HTTPAnnRequest(std::unique_ptr rg) + : rg_{std::move(rg)} {} HTTPAnnRequest::~HTTPAnnRequest() @@ -275,10 +275,9 @@ void TrackerWatcherCommand::addConnection() } } -std::shared_ptr +std::unique_ptr TrackerWatcherCommand::createAnnounce(DownloadEngine* e) { - std::shared_ptr treq; while(!btAnnounce_->isAllAnnounceFailed() && btAnnounce_->isAnnounceReady()) { std::string uri = btAnnounce_->getAnnounceUrl(); @@ -287,6 +286,7 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e) if(uri_split(&res, uri.c_str()) == 0) { // Without UDP tracker support, send it to normal tracker flow // and make it fail. + std::unique_ptr treq; if(udpTrackerClient_ && uri::getFieldString(res, USR_SCHEME, uri.c_str()) == "udp") { uint16_t localPort; @@ -298,7 +298,7 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e) treq = createHTTPAnnRequest(btAnnounce_->getAnnounceUrl()); } btAnnounce_->announceStart(); // inside it, trackers++. - break; + return treq; } else { btAnnounce_->announceFailure(); } @@ -306,17 +306,16 @@ TrackerWatcherCommand::createAnnounce(DownloadEngine* e) if(btAnnounce_->isAllAnnounceFailed()) { btAnnounce_->resetAnnounce(); } - return treq; + return nullptr; } -std::shared_ptr +std::unique_ptr TrackerWatcherCommand::createUDPAnnRequest(const std::string& host, uint16_t port, uint16_t localPort) { - std::shared_ptr req = - btAnnounce_->createUDPTrackerRequest(host, port, localPort); - return std::shared_ptr(new UDPAnnRequest(req)); + return make_unique + (btAnnounce_->createUDPTrackerRequest(host, port, localPort)); } namespace { @@ -338,13 +337,13 @@ bool backupTrackerIsAvailable } } // namespace -std::shared_ptr +std::unique_ptr TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri) { std::vector uris; uris.push_back(uri); - std::shared_ptr