Re: [asio-users] Checking for success with in a TCP client
Brought to you by:
chris_kohlhoff
From: Christopher K. <ch...@ko...> - 2007-10-30 06:04:01
|
Simon Pickles wrote: > So the line: > > else if (endpoint_iterator != tcp::resolver::iterator()) > > isn't true if the server is not available. Eek, too many negatives! :) > What exactly does this line do? It tests whether you have reached the end of the list of endpoints returned as a result of the name resolution. In the context of your code, it says that you haven't yet exhausted your connection attempts. >> else if (endpoint_iterator != tcp::resolver::iterator()) >> { >> g_log->CLIENT("Connection unsuccessful\n"); >> m_socket.close(); >> g_log->CLIENT("Retrying\n"); >> tcp::endpoint endpoint = *endpoint_iterator; >> m_socket.async_connect( endpoint, >> boost::bind( &ASIOClient::HandleConnect, >> this, >> >> boost::asio::placeholders::error, ++endpoint_iterator)); >> } >> >> } >> >> >> Is seems the error isn't caught by the else. Try adding an additional else branch: else { g_log->CLIENT("No more endpoints to try, giving up\n"); } Cheers, Chris |