title: boost::asio::async_resolve Problem
body: <p>I'm in the process of constructing a Socket class that uses <code>boost::asio</code>.  To start with, I made a <code>connect</code> method that took a host and a port and resolved it to an IP address.  This worked well, so I decided to look in to <code>async_resolve</code>.  However, my callback always gets an error code of <code>995</code> (using the same destination host/port as when it worked synchronously).</p>
  
  <p><strong>code</strong>:</p>
  
  <p>Function that starts the resolution:</p>
  
  <pre><code>  // resolve a host asynchronously
    template&lt;typename ResolveHandler&gt;
    void resolveHost(const String&amp; _host, Port _port, ResolveHandler _handler) const
    {
     boost::asio::ip::tcp::endpoint ret;
     boost::asio::ip::tcp::resolver::query query(_host, boost::lexical_cast&lt;std::string&gt;(_port));
     boost::asio::ip::tcp::resolver r(m_IOService);
     r.async_resolve(query, _handler);
    }; // eo resolveHost
  </code></pre>
  
  <p>Code that calls this function:</p>
  
  <pre><code>  void Socket::connect(const String&amp; _host, Port _port)
    {
     // Anon function for resolution of the host-name and asynchronous calling of the above
     auto anonResolve = [this](const boost::system::error_code&amp; _errorCode, 
             boost::asio::ip::tcp::resolver_iterator _epIt)
     {
      // raise event
      onResolve.raise(SocketResolveEventArgs(*this, !_errorCode ? (*_epIt).host_name() : String(""), _errorCode));
  
      // perform connect, calling back to anonymous function
      if(!_errorCode)
       connect(*_epIt);
     };
  
     // Resolve the host calling back to anonymous function
     Root::instance().resolveHost(_host, _port, anonResolve);
  
    }; // eo connect
  </code></pre>
  
  <p>The <code>message()</code> function of the <code>error_code</code> is:</p>
  
  <pre><code>The I/O operation has been aborted because of either a thread exit or an application request
  </code></pre>
  
  <p>And my <code>main.cpp</code> looks like this:</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
   morse::Root root;
   TextSocket s;
   s.connect("somehost.com", 1234);
   while(true)
   {
    root.performIO(); // calls io_service::run_one()
   }
   return 0;
  }
  </code></pre>
  
  <p>Thanks in advance!</p>