Use std::unique_ptr for AsyncResolverMan

pull/103/head
Tatsuhiro Tsujikawa 2013-07-03 01:30:01 +09:00
parent 74d6d64271
commit 0d85fb0df3
6 changed files with 12 additions and 13 deletions

View File

@ -91,7 +91,7 @@ AbstractCommand::AbstractCommand
req_(req), fileEntry_(fileEntry), e_(e), socket_(s), req_(req), fileEntry_(fileEntry), e_(e), socket_(s),
socketRecvBuffer_(socketRecvBuffer), socketRecvBuffer_(socketRecvBuffer),
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
asyncNameResolverMan_(new AsyncNameResolverMan()), asyncNameResolverMan_(make_unique<AsyncNameResolverMan>()),
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
checkSocketIsReadable_(false), checkSocketIsWritable_(false), checkSocketIsReadable_(false), checkSocketIsWritable_(false),
incNumConnection_(incNumConnection), incNumConnection_(incNumConnection),

View File

@ -76,7 +76,7 @@ private:
std::vector<std::shared_ptr<Segment> > segments_; std::vector<std::shared_ptr<Segment> > segments_;
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_; std::unique_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
bool checkSocketIsReadable_; bool checkSocketIsReadable_;

View File

@ -94,13 +94,13 @@ void AsyncNameResolverMan::startAsyncFamily(const std::string& hostname,
DownloadEngine* e, DownloadEngine* e,
Command* command) Command* command)
{ {
asyncNameResolver_[numResolver_].reset asyncNameResolver_[numResolver_] = std::make_shared<AsyncNameResolver>
(new AsyncNameResolver(family (family
#ifdef HAVE_ARES_ADDR_NODE #ifdef HAVE_ARES_ADDR_NODE
, ,
e->getAsyncDNSServers() e->getAsyncDNSServers()
#endif // HAVE_ARES_ADDR_NODE #endif // HAVE_ARES_ADDR_NODE
)); );
asyncNameResolver_[numResolver_]->resolve(hostname); asyncNameResolver_[numResolver_]->resolve(hostname);
setNameResolverCheck(numResolver_, e, command); setNameResolverCheck(numResolver_, e, command);
} }
@ -111,9 +111,8 @@ const
for(size_t i = 0; i < numResolver_; ++i) { for(size_t i = 0; i < numResolver_; ++i) {
if(asyncNameResolver_[i]->getStatus() == if(asyncNameResolver_[i]->getStatus() ==
AsyncNameResolver::STATUS_SUCCESS) { AsyncNameResolver::STATUS_SUCCESS) {
const std::vector<std::string>& addrs = auto& addrs = asyncNameResolver_[i]->getResolvedAddresses();
asyncNameResolver_[i]->getResolvedAddresses(); res.insert(std::end(res), std::begin(addrs), std::end(addrs));
res.insert(res.end(), addrs.begin(), addrs.end());
} }
} }
return; return;

View File

@ -59,7 +59,7 @@ private:
DownloadEngine* e_; DownloadEngine* e_;
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_; std::unique_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
DHTTaskQueue* taskQueue_; DHTTaskQueue* taskQueue_;

View File

@ -58,7 +58,7 @@ NameResolveCommand::NameResolveCommand
: Command(cuid), : Command(cuid),
e_(e), e_(e),
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
asyncNameResolverMan_(new AsyncNameResolverMan()), asyncNameResolverMan_(make_unique<AsyncNameResolverMan>()),
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
req_(req) req_(req)
{ {

View File

@ -55,7 +55,7 @@ private:
DownloadEngine* e_; DownloadEngine* e_;
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
std::shared_ptr<AsyncNameResolverMan> asyncNameResolverMan_; std::unique_ptr<AsyncNameResolverMan> asyncNameResolverMan_;
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS