[Boost-bugs] [Boost C++ Libraries] #6138: ip::tcp::resolver::cancel problem

Subject: [Boost-bugs] [Boost C++ Libraries] #6138: ip::tcp::resolver::cancel problem
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-11-18 09:28:30


#6138: ip::tcp::resolver::cancel problem
------------------------------+---------------------------------------------
 Reporter: forever | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.48.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 If connection is down, `boost::asio::ip::tcp::resolver::cancel' doesn't
 work properly by attemting to resolve a host using
 `boost::asio::ip::tcp::resolver::async_resolve'.

 Handler has invoked with the code `host_not_found_try_again' and not
 `operation_aborted'.

 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.

 [http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/reference/ip__basic_resolver/cancel.html
 Link]

 {{{
 #include <iostream>
 #include <boost/asio.hpp>

 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 = [&](const boost::system::error_code& e,
 boost::asio::ip::tcp::resolver::iterator it) {
       if ( e ) { std::cout << "e: " << e.message() << std::endl; }
       if ( it == boost::asio::ip::tcp::resolver::iterator() ) { std::cout
 << "null iterator" << std::endl; }
       if ( e || it == boost::asio::ip::tcp::resolver::iterator() ) {
 return; }

       for ( ; it != boost::asio::ip::tcp::resolver::iterator(); ++it) {
          std::cout << "it: " << it->endpoint() << std::endl;
       }
    };

    resolver.async_resolve(
       query,
       func
    );

    timer.expires_from_now(boost::posix_time::milliseconds(1000));
    timer.async_wait(
       [&](const boost::system::error_code& error){
          std::cout << "timer expired" << std::endl;
          resolver.cancel();
       }
    );
    ios.run();
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6138>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC