boost::asio and resolve_async

I was looking at needing to do a large number of reverse DNS lookups for a log analysis program I am writing, and wanted to use some form of async lookup to speed the program up (vs. doing each look up in series, at a couple of seconds per lookup). boost::asio and the async_resolve functions looked to be just what I wanted, BUT: I can find no good examples of a simple lookup. By "simple" I mean "given an address, give me the host name(s) associated with that address". All the examples were for a lookup by host name/transport type/port, e.g. host name/tcp/80. In my case I neither need a port # nor even have one - I just want the RDNS for the address. It seems to me the documentation in the boost::asio is a bit light on the various types for resolver queries, endpoint types, and such - and seems to be more focused on TCP and UDP than generic IP. Are there any better examples out there of RDNS using boost::asio?

On 8/16/2012 9:35 AM, david.hagood@gmail.com wrote:
I was looking at needing to do a large number of reverse DNS lookups for a log analysis program I am writing, and wanted to use some form of async lookup to speed the program up (vs. doing each look up in series, at a couple of seconds per lookup).
Note: "An additional thread per io_service is used to emulate asynchronous host resolution. This thread is created on the first call to either ip::tcp::resolver::async_resolve() or ip::udp::resolver::async_resolve()." from http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/overview/implementa...
boost::asio and the async_resolve functions looked to be just what I wanted, BUT: I can find no good examples of a simple lookup. By "simple" I mean "given an address, give me the host name(s) associated with that address". All the examples were for a lookup by host name/transport type/port, e.g. host name/tcp/80. In my case I neither need a port # nor even have one - I just want the RDNS for the address.
namespace { void handle_resolve(const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator ep_it) { if (!ec) { // print ip addresses for (boost::asio::ip::tcp::resolver::iterator end; ep_it != end; ++ep_it) { std::cout << ep_it->host_name() << ": " << ep_it->endpoint().address().to_string() << std::endl; } } else { std::cerr << "Resolve error: " << ec << std::endl; } } } BOOST_AUTO_TEST_CASE(test_async_resolve) { boost::asio::io_service io_service; boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::query query1("www.google.com", ""); boost::asio::ip::tcp::resolver::query query2("www.yahoo.com", ""); boost::asio::ip::tcp::resolver::query query3("www.boost.org", ""); boost::asio::ip::tcp::resolver::query query4("www.ociweb.com", ""); resolver.async_resolve(query1, boost::bind(&handle_resolve, _1, _2)); resolver.async_resolve(query2, boost::bind(&handle_resolve, _1, _2)); resolver.async_resolve(query3, boost::bind(&handle_resolve, _1, _2)); resolver.async_resolve(query4, boost::bind(&handle_resolve, _1, _2)); io_service.run(); } KevinH -- Kevin Heifner heifnerk@ociweb.com Object Computing, Inc. www.ociweb.com
participants (2)
-
david.hagood@gmail.com
-
Kevin Heifner