boost::asio::ip::tcp::resolver::query does not work in Ubuntu!!!

Hi, I am a newbie with Asio library and i got into crashing problem with the following code: boost::system::error_code ec; boost::asio::ip::tcp::resolver resolver( m_hive->GetService() ); 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 ); When i run this in windows, i do not have any isssue but in Ubuntu, it works and after some more resolution of query, it crashes. I did install Miredo to activate Ipv6 but it did not help. When the crash happens, i see this: 23:37.47 [dbg] [0x8ec0650] Exception: Host not found (authoritative) 23:37.47 [dbg] [0x8ec0650] Exception: Host not found (authoritative) terminate called after throwing an instance of 'boost::exception_detail::clone_implboost::exception_detail::error_info_injector<boost::system::system_error
' what(): Host not found (authoritative) Aborted (core dumped)
Do you know what else is missing or what is wrong? Thanks a lot, mustafa -- 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.

Hi,
I am a newbie with Asio library and i got into crashing problem with the following code:
boost::system::error_code ec; boost::asio::ip::tcp::resolver resolver( m_hive->GetService() ); 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 );
When i run this in windows, i do not have any isssue but in Ubuntu, it works and after some more resolution of query, it crashes. I did install Miredo to activate Ipv6 but it did not help.
When the crash happens, i see this:
23:37.47 [dbg] [0x8ec0650] Exception: Host not found (authoritative) 23:37.47 [dbg] [0x8ec0650] Exception: Host not found (authoritative) terminate called after throwing an instance of 'boost::exception_detail::clone_implboost::exception_detail::error_info_injector<boost::system::system_error
' what(): Host not found (authoritative) Aborted (core dumped)
Do you know what else is missing or what is wrong?
Thanks a lot, mustafa
Provided your output, this is not a crash but just the case of an unhandled exception. Take a look at this: http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/ip__basic... It says that resolve() throws an exception on error so you can either catch it or use the overload where you need to provide an error handle yourself (which is not much different since you need to handle errors anyway). Regards, Andreas

HI Andreas,
you are right. this is not crash. It is an exception.
I did the following small code to explain the issue better
============================================
#include <iostream>
#include

Zitat von mozdemir
HI Andreas,
you are right. this is not crash. It is an exception.
I did the following small code to explain the issue better
============================================
#include <iostream> #include
#include using namespace boost::asio;
int main(int argc, char* argv[]) { io_service ios; try { int i; for (i=0;i<1000;i++) { 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; } }
} catch(std::exception const& ex) { std::cerr << "Error: " << ex.what() << '\n'; } } =============================================
the output goes fine but around 300, it throws the exception.
i: 327 ip: 98.139.183.24 i: 328 ip: 98.139.183.24 i: 329 ip: 98.139.183.24
Error: Host not found (authoritative)
============================================
you are suggesting to handle the exception which I will do. But i wonder why this is not happening in windows but ubuntu?
I wonder if my ubuntu is missing some configuration. I did install Miredo for Ipv6 but it did not help. i feel like this is something to do with network settings issue, NAT issue or something....
Thank you for the suggestion. mustafa
I'm not sure right now whether it is against the policy of this mailing list, but take a look at this: http://stackoverflow.com/questions/4956915/how-can-i-adapt-this-c-testcase-s... This looks similar to your example. Let us know if it helped. Regards, Andreas

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
participants (2)
-
Andreas Wehrmann
-
mozdemir