title: Boost async_read
body: <p>I'm trying to create a TCP server where the Start() method blocks until a connection is accepted, and then begins a series of asynchronous reads.  I have the following code, and when I connect using telnet I get this output:</p>
  <blockquote>
  <p>Waiting for a new connection</p>
  <p>Connection accepted</p>
  <p>terminate called throwing an exceptionAbort trap: 6</p>
  </blockquote>
  <p>Here is the code:</p>
  <pre><code>void SocketReadThread::Start()
  {
      bzero(m_headerBuffer, HEADER_LEN);
      m_running = true;
  
      asio::io_service ios;
      asio::ip::tcp::acceptor acp (ios,
          boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), GUI_PORT));
  
      asio::ip::tcp::socket sock(ios);
      std::cout &lt;&lt; &quot;Waiting for a new connection&quot; &lt;&lt; std::endl;
  
      acp.accept(sock); 
      std::cout &lt;&lt; &quot;Connection accepted&quot; &lt;&lt; std::endl;
  
      asio::async_read(sock, asio::buffer(m_headerBuffer, HEADER_LEN),
          boost::bind(&amp;SocketReadThread::handleReadHeader, shared_from_this(),
          asio::placeholders::error));
  
      ios.run();
  }
  
  void SocketReadThread::handleReadHeader(const system::error_code&amp; error)
  {
      std::cout &lt;&lt; &quot;Read two bytes!&quot; &lt;&lt; std::endl;
  }
  </code></pre>