Hi Andreas,
I have changed the code like below in the light of the link you sent.
it did help for sure. The stats comparing both case are:
1. Without res_init(), the frequency is around 6 exceptions after 2047
resolutions:
totalRes: 2047 errorNum: 6 Error: Host not found (authoritative)
2. with res_init(), in the first run i saw 2 exceptions out of 2000 but
later on i run it long time and did not see any exceptions!
Hopefully, this is the right fix. I leave the code below to help others.
Thanks a lot,
mustafa
================================================
#include <iostream>
#include
#include
#include
#include
#include
using namespace boost::asio;
int main(int argc, char* argv[])
{
io_service ios;
int errorNum = 0;
int totalRes = 0;
while (true) {
try {
int i;
for (i=0;i<1000;i++) {
res_init();
int m_port = 80;
std::string m_host = "www.yahoo.com";
boost::system::error_code ec;
boost::asio::ip::tcp::resolver resolver( ios );
boost::asio::ip::tcp::resolver::query query( m_host,
boost::lexical_cast< std::string >( m_port ));
boost::asio::ip::tcp::resolver::iterator endpointIterator =
resolver.resolve( query );
for (;endpointIterator != ip::tcp::resolver_iterator();
++endpointIterator) {
std::cout << "i: " << i << " ip: " <<
endpointIterator->endpoint().address().to_string() << std::endl;
totalRes++;
}
boost::this_thread::sleep(boost::posix_time::milliseconds(
100 ));
}
} catch (std::exception const& ex) {
errorNum++;
std::cerr << "totalRes: " << totalRes << " errorNum: " <<
errorNum <<" Error: " << ex.what() << '\n';
boost::this_thread::sleep(boost::posix_time::milliseconds( 3000
));
}
}
return 0;
}
========================================================
--
View this message in context: http://boost.2283326.n4.nabble.com/boost-asio-ip-tcp-resolver-query-does-not...
Sent from the Boost - Users mailing list archive at Nabble.com.