Boost C++ Libraries: Ticket #6138: ip::tcp::resolver::cancel problem https://svn.boost.org/trac10/ticket/6138 <p> If connection is down, <code>boost::asio::ip::tcp::resolver::cancel' doesn't work properly by attemting to resolve a host using </code>boost::asio::ip::tcp::resolver::async_resolve'. </p> <p> Handler has invoked with the code <code>host_not_found_try_again' and not </code>operation_aborted'. </p> <p> Though it's documented that function forces the completion of any pending asynchronous operations on the host resolver, the handler for each cancelled operation will be invoked with the `boost::asio::error::operation_aborted' error code. </p> <p> <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/reference/ip__basic_resolver/cancel.html">Link</a> </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; int main() { boost::asio::io_service ios; boost::asio::deadline_timer timer(ios); boost::asio::ip::tcp::resolver resolver(ios); boost::asio::ip::tcp::resolver::query query("google.ru", "http"); auto func = [&amp;](const boost::system::error_code&amp; e, boost::asio::ip::tcp::resolver::iterator it) { if ( e ) { std::cout &lt;&lt; "e: " &lt;&lt; e.message() &lt;&lt; std::endl; } if ( it == boost::asio::ip::tcp::resolver::iterator() ) { std::cout &lt;&lt; "null iterator" &lt;&lt; std::endl; } if ( e || it == boost::asio::ip::tcp::resolver::iterator() ) { return; } for ( ; it != boost::asio::ip::tcp::resolver::iterator(); ++it) { std::cout &lt;&lt; "it: " &lt;&lt; it-&gt;endpoint() &lt;&lt; std::endl; } }; resolver.async_resolve( query, func ); timer.expires_from_now(boost::posix_time::milliseconds(1000)); timer.async_wait( [&amp;](const boost::system::error_code&amp; error){ std::cout &lt;&lt; "timer expired" &lt;&lt; std::endl; resolver.cancel(); } ); ios.run(); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6138 Trac 1.4.3 chris_kohlhoff Tue, 29 May 2012 01:39:02 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6138#comment:1 https://svn.boost.org/trac10/ticket/6138#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Cancellation is best effort. As your connection is down, the resolve operation is already in progress (and no longer really "pending") and so cannot be cancelled. </p> Ticket