@@ -43,7 +43,7 @@ class AresResolver : public Resolver,
4343 if (timeout_ == 0 ||
4444 cachedAddr.second .after (timeout_) > trantor::Date::date ())
4545 {
46- inet = (cachedAddr.first )[0 ];
46+ inet = (* cachedAddr.first )[0 ];
4747 cached = true ;
4848 }
4949 }
@@ -75,8 +75,7 @@ class AresResolver : public Resolver,
7575 virtual void resolve (const std::string& hostname,
7676 const ResolverResultsCallback& cb) override
7777 {
78- bool cached = false ;
79- std::vector<trantor::InetAddress> inets;
78+ std::shared_ptr<std::vector<trantor::InetAddress>> inets_ptr{nullptr };
8079 {
8180 std::lock_guard<std::mutex> lock (globalMutex ());
8281 auto iter = globalCache ().find (hostname);
@@ -86,14 +85,13 @@ class AresResolver : public Resolver,
8685 if (timeout_ == 0 ||
8786 cachedAddr.second .after (timeout_) > trantor::Date::date ())
8887 {
89- inets = cachedAddr.first ;
90- cached = true ;
88+ inets_ptr = cachedAddr.first ;
9189 }
9290 }
9391 }
94- if (cached )
92+ if (inets_ptr )
9593 {
96- cb (inets );
94+ cb (*inets_ptr );
9795 return ;
9896 }
9997 if (loop_->isInLoopThread ())
@@ -132,12 +130,14 @@ class AresResolver : public Resolver,
132130 ChannelList channels_;
133131 static std::unordered_map<
134132 std::string,
135- std::pair<std::vector<InetAddress>, trantor::Date>>&
133+ std::pair<std::shared_ptr<std::vector<trantor::InetAddress>>,
134+ trantor::Date>>&
136135 globalCache ()
137136 {
138137 static std::unordered_map<
139138 std::string,
140- std::pair<std::vector<InetAddress>, trantor::Date>>
139+ std::pair<std::shared_ptr<std::vector<trantor::InetAddress>>,
140+ trantor::Date>>
141141 dnsCache;
142142 return dnsCache;
143143 }
0 commit comments