title: Boost::Asio Async write failed
body: <p>I am porting an application which uses Boost::Asio to an embedded system.</p>
  
  <p>I have already cross-compiled boost 1.57.0 binaries for the board using its BSP.  To test the libraries working, I ran two http server examples that use synchronized and asynchronized writing respectively.</p>
  
  <p>The Sync version runs fine; while the Async one failed at writing.  It returned error "Operation canceled".  </p>
  
  <p>Can anyone point out where I should look for?  Thanks.</p>
  
  <pre><code>/*
   * Boost::Asio async example
   */
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;boost/asio.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/smart_ptr.hpp&gt;
  
  using namespace boost::asio;
  using boost::system::error_code;
  using ip::tcp;
  
  struct CHelloWorld_Service
  {
          CHelloWorld_Service(io_service &amp;iosev)
                  :m_iosev(iosev),m_acceptor(iosev, tcp::endpoint(tcp::v4(), 1000))
          {}
  
          void start()
          {
                  boost::shared_ptr&lt;tcp::socket&gt; psocket(new tcp::socket(m_iosev));
                  m_acceptor.async_accept(*psocket,
                          boost::bind(&amp;CHelloWorld_Service::accept_handler, this, psocket, _1));
          }
  
          void accept_handler(boost::shared_ptr&lt;tcp::socket&gt; psocket, error_code ec)
          {
                  if(ec) return;
                  start();
                  std::cout &lt;&lt; psocket-&gt;remote_endpoint().address() &lt;&lt; std::endl;
                  boost::shared_ptr&lt;std::string&gt; pstr(new std::string("hello async world!"));
                  psocket-&gt;async_write_some(buffer(*pstr),
                          boost::bind(&amp;CHelloWorld_Service::write_handler, this, pstr, _1, _2));
          }
  
          void write_handler(boost::shared_ptr&lt;std::string&gt; pstr, error_code ec,
                  size_t bytes_transferred)
          {
                  if(ec)
                  std::cout&lt;&lt; "Failed to send! " &lt;&lt; boost::system::system_error(ec).what() &lt;&lt; std::endl;
                  else
                  std::cout&lt;&lt; *pstr &lt;&lt; " has been sent" &lt;&lt; std::endl;
          }
  
          private:
                  io_service &amp;m_iosev;
                  ip::tcp::acceptor m_acceptor;
  };
  
  int main(int argc, char* argv[])
  {
          io_service iosev;
          CHelloWorld_Service sev(iosev);
          sev.start();
          iosev.run();
  
          return 0;
  }
  </code></pre>