diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-07-06 20:58:09 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-07-06 21:00:57 +0900 |
| commit | 3c66c18489bb7e4f828fc5107299174cbc4ee4e5 (patch) | |
| tree | dfcc32b58dbf490637bcdbad1575a48ac0e4e5d6 /src | |
| parent | 5378ed8c431045a211af4c0b078ca9de6369f2d2 (diff) | |
TrackerWatcherCommand: Use std::unique_ptr for trackerRequest_
Diffstat (limited to 'src')
| -rw-r--r-- | src/TrackerWatcherCommand.cc | 37 | ||||
| -rw-r--r-- | src/TrackerWatcherCommand.h | 12 |
2 files changed, 24 insertions, 25 deletions
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc index 303b0c64..0cb057a4 100644 --- a/src/TrackerWatcherCommand.cc +++ b/src/TrackerWatcherCommand.cc @@ -70,8 +70,8 @@ namespace aria2 { -HTTPAnnRequest::HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg) - : rg_(rg) +HTTPAnnRequest::HTTPAnnRequest(std::unique_ptr<RequestGroup> rg) + : rg_{std::move(rg)} {} HTTPAnnRequest::~HTTPAnnRequest() @@ -275,10 +275,9 @@ void TrackerWatcherCommand::addConnection() } } -std::shared_ptr<AnnRequest> +std::unique_ptr<AnnRequest> TrackerWatcherCommand::createAnnounce(DownloadEngine* e) { - std::shared_ptr<AnnRequest> 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<AnnRequest> 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<AnnRequest> +std::unique_ptr<AnnRequest> TrackerWatcherCommand::createUDPAnnRequest(const std::string& host, uint16_t port, uint16_t localPort) { - std::shared_ptr<UDPTrackerRequest> req = - btAnnounce_->createUDPTrackerRequest(host, port, localPort); - return std::shared_ptr<AnnRequest>(new UDPAnnRequest(req)); + return make_unique<UDPAnnRequest> + (btAnnounce_->createUDPTrackerRequest(host, port, localPort)); } namespace { @@ -338,13 +337,13 @@ bool backupTrackerIsAvailable } } // namespace -std::shared_ptr<AnnRequest> +std::unique_ptr<AnnRequest> TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri) { std::vector<std::string> uris; uris.push_back(uri); - std::shared_ptr<Option> option = util::copy(getOption()); - std::shared_ptr<RequestGroup> rg(new RequestGroup(GroupId::create(), option)); + auto option = util::copy(getOption()); + auto rg = make_unique<RequestGroup>(GroupId::create(), option); if(backupTrackerIsAvailable(requestGroup_->getDownloadContext())) { A2_LOG_DEBUG("This is multi-tracker announce."); } else { @@ -363,13 +362,13 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri) option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT)); option->put(PREF_REUSE_URI, A2_V_FALSE); option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE); - std::shared_ptr<DownloadContext> dctx - (new DownloadContext(option->getAsInt(PREF_PIECE_LENGTH), - 0, - "[tracker.announce]")); + auto dctx = std::make_shared<DownloadContext> + (option->getAsInt(PREF_PIECE_LENGTH), + 0, + "[tracker.announce]"); dctx->getFileEntries().front()->setUris(uris); rg->setDownloadContext(dctx); - std::shared_ptr<DiskWriterFactory> dwf(new ByteArrayDiskWriterFactory()); + auto dwf = std::make_shared<ByteArrayDiskWriterFactory>(); rg->setDiskWriterFactory(dwf); rg->setFileAllocationEnabled(false); rg->setPreLocalFileCheckEnabled(false); @@ -380,7 +379,7 @@ TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri) dctx->setAcceptMetalink(false); A2_LOG_INFO(fmt("Creating tracker request group GID#%s", GroupId::toHex(rg->getGID()).c_str())); - return std::shared_ptr<AnnRequest>(new HTTPAnnRequest(rg)); + return make_unique<HTTPAnnRequest>(std::move(rg)); } void TrackerWatcherCommand::setBtRuntime diff --git a/src/TrackerWatcherCommand.h b/src/TrackerWatcherCommand.h index 2e6f20fa..920e4328 100644 --- a/src/TrackerWatcherCommand.h +++ b/src/TrackerWatcherCommand.h @@ -70,7 +70,7 @@ public: class HTTPAnnRequest:public AnnRequest { public: - HTTPAnnRequest(const std::shared_ptr<RequestGroup>& rg); + HTTPAnnRequest(std::unique_ptr<RequestGroup> rg); virtual ~HTTPAnnRequest(); virtual bool stopped() const CXX11_OVERRIDE; virtual bool success() const CXX11_OVERRIDE; @@ -79,7 +79,7 @@ public: virtual bool processResponse(const std::shared_ptr<BtAnnounce>& btAnnounce) CXX11_OVERRIDE; private: - std::shared_ptr<RequestGroup> rg_; + std::unique_ptr<RequestGroup> rg_; }; class UDPAnnRequest:public AnnRequest { @@ -113,16 +113,16 @@ private: 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 * is needed. */ - std::shared_ptr<AnnRequest> + std::unique_ptr<AnnRequest> createHTTPAnnRequest(const std::string& uri); - std::shared_ptr<AnnRequest> + std::unique_ptr<AnnRequest> createUDPAnnRequest(const std::string& host, uint16_t port, uint16_t localPort); @@ -136,7 +136,7 @@ public: virtual ~TrackerWatcherCommand(); - std::shared_ptr<AnnRequest> createAnnounce(DownloadEngine* e); + std::unique_ptr<AnnRequest> createAnnounce(DownloadEngine* e); virtual bool execute() CXX11_OVERRIDE; |
