auto dns(Func handler, boost::asio::ip::tcp::resolver& resolver, std::string address, std::string port) { boost::asio::ip::tcp::resolver::query query(address, port); return resolver.async_resolve(query, handler); }
void do_work (CompletionCounter) { if (m_called_stop.load () == 1) return; // We don't have any work to do at this time if (m_work.empty()) { m_idle = true; m_journal.trace << "Sleeping"; return; } if (m_work.front().names.empty()) m_work.pop_front(); std::string const name (m_work.front().names.back()); HandlerType handler (m_work.front().handler); m_work.front().names.pop_back(); HostAndPort const hp (parseName(name)); if (hp.first.empty()) { m_journal.error << "Unable to parse '" << name << "'"; m_io_service.post (m_strand.wrap (boost::bind ( &NameResolverImpl::do_work, this, CompletionCounter(this)))); return; } boost::asio::ip::tcp::resolver::query query ( hp.first, hp.second); m_resolver.async_resolve (query, boost::bind ( &NameResolverImpl::do_finish, this, name, boost::asio::placeholders::error, handler, boost::asio::placeholders::iterator, CompletionCounter(this))); }
void do_work (CompletionCounter) { if (m_stop_called == true) return; // We don't have any work to do at this time if (m_work.empty ()) return; std::string const name (m_work.front ().names.back()); HandlerType handler (m_work.front ().handler); m_work.front ().names.pop_back (); if (m_work.front ().names.empty ()) m_work.pop_front(); HostAndPort const hp (parseName (name)); if (hp.first.empty ()) { JLOG(m_journal.error()) << "Unable to parse '" << name << "'"; m_io_service.post (m_strand.wrap (std::bind ( &ResolverAsioImpl::do_work, this, CompletionCounter (this)))); return; } boost::asio::ip::tcp::resolver::query query ( hp.first, hp.second); m_resolver.async_resolve (query, std::bind ( &ResolverAsioImpl::do_finish, this, name, std::placeholders::_1, handler, std::placeholders::_2, CompletionCounter (this))); }
void start() { if (!_cancelled) _resolver.async_resolve(_q, boost::bind(&FriendConnector::hostResolved, shared_from_this(), asio::placeholders::error, asio::placeholders::iterator)); }