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),
socketRecvBuffer_(socketRecvBuffer),
#ifdef ENABLE_ASYNC_DNS
asyncNameResolverMan_(new AsyncNameResolverMan()),
asyncNameResolverMan_(make_unique<AsyncNameResolverMan>()),
#endif // ENABLE_ASYNC_DNS
checkSocketIsReadable_(false), checkSocketIsWritable_(false),
incNumConnection_(incNumConnection),

View File

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

View File

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

View File

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

View File

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

View File

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