29 typedef boost::asio::ip::udp::endpoint
EndPoint;
30 typedef boost::asio::ip::basic_resolver<boost::asio::ip::udp>
BoostResolver;
38 boost::asio::io_service& ioService)
39 : m_resolver(ioService)
40 , m_addressSelector(addressSelector)
41 , m_onSuccess(onSuccess)
43 , m_scheduler(ioService)
49 const time::nanoseconds& timeout,
50 const shared_ptr<Resolver>&
self)
52 BoostResolver::query query(host,
NULL_PORT);
56 m_resolveTimeout = m_scheduler.scheduleEvent(timeout,
64 return m_resolver.resolve(query);
70 const shared_ptr<Resolver>&
self)
72 m_scheduler.cancelEvent(m_resolveTimeout);
76 if (error == boost::system::errc::operation_canceled)
81 return m_onError(
"Remote endpoint hostname or port cannot be resolved: " +
82 error.category().message(error.value()));
86 for (; remoteEndpoint != end; ++remoteEndpoint)
90 if (m_addressSelector(address))
92 return m_onSuccess(address);
96 m_onError(
"No endpoint matching the specified address selector found");
103 m_onError(errorInfo);
110 BoostResolver m_resolver;
117 Scheduler m_scheduler;
126 boost::asio::io_service& ioService,
128 const time::nanoseconds& timeout)
130 shared_ptr<Resolver> resolver = make_shared<Resolver>(onSuccess, onError,
131 addressSelector, ndn::ref(ioService));
132 resolver->asyncResolve(host, timeout, resolver);
137 syncResolve(
const std::string& host, boost::asio::io_service& ioService,
142 BoostResolver::query query(host, Resolver::NULL_PORT);
147 for (; remoteEndpoint != end; ++remoteEndpoint)
149 if (addressSelector(
EndPoint(*remoteEndpoint).address()))
151 return EndPoint(*remoteEndpoint).address();
154 BOOST_THROW_EXCEPTION(
Error(
"No endpoint matching the specified address selector found"));
Copyright (c) 2011-2015 Regents of the University of California.
static const std::string NULL_PORT
Resolver(const SuccessCallback &onSuccess, const ErrorCallback &onError, const ndn::dns::AddressSelector &addressSelector, boost::asio::io_service &ioService)
function< bool(const boost::asio::ip::address &address)> AddressSelector
boost::asio::ip::udp::endpoint EndPoint
function< void(const IpAddress &address)> SuccessCallback
std::shared_ptr< ns3::EventId > EventId
function< void(const std::string &reason)> ErrorCallback
void asyncResolve(const std::string &host, const time::nanoseconds &timeout, const shared_ptr< Resolver > &self)
void onResolveError(const std::string &errorInfo, const shared_ptr< Resolver > &self)
Table::const_iterator iterator
boost::asio::ip::basic_resolver< boost::asio::ip::udp > BoostResolver
boost::asio::ip::address IpAddress
void onResolveSuccess(const boost::system::error_code &error, BoostResolver::iterator remoteEndpoint, const shared_ptr< Resolver > &self)
BoostResolver::iterator syncResolve(BoostResolver::query query)