title: Why is client getting EOF on async_write?
body: <p>I'm writing an asynchronous server using boost::asio. I changed boost HTTP server example to use only simple protobufs. Now client gets <code>libc++abi.dylib: terminating with uncaught exception of type boost::wrapexcept&lt;boost::system::system_error&gt;: read: End of file</code> error when server's trying to send message using async_write.</p>
  
  <p>I have tried sync and async clients, different types of buffers but the problem is still there. All the things are going well until async_write.</p>
  
  <pre><code>        void TConnection::DoRead() {
              std::cout &lt;&lt; "Reading data" &lt;&lt; std::endl;
              auto self(shared_from_this());
              Socket.async_read_some(boost::asio::buffer(Buffer),
                                      [this, self](boost::system::error_code ec, std::size_t bytes_transferred)
                                      {
                                          if (!ec) {
                                              TRequestParser::ResultType result;
                                              TMessage request;
                                              request.Parse(Buffer.data(), bytes_transferred);
                                              Reply = MasterPtr-&gt;HandleMessange(request);
                                              std::cout &lt;&lt; "Replying: " &lt;&lt; Reply.Content &lt;&lt; std::endl;
                                              DoWrite();
                                          } else if (ec != boost::asio::error::operation_aborted) {
                                              ConnectionManager.Stop(shared_from_this());
                                          }
                                      });
          }
  
          void TConnection::DoWrite() {
              std::cout &lt;&lt; "Writing data" &lt;&lt; std::endl;
              auto self(shared_from_this());
              std::cout &lt;&lt; "Replying2: " &lt;&lt; Reply.Content &lt;&lt; std::endl;
              Reply.ToStreamBuf(&amp;Streambuf);
              std::cout &lt;&lt; "Now I'm gonna write" &lt;&lt; std::endl;
              std::cout &lt;&lt; Streambuf.size() &lt;&lt; std::endl;
              boost::asio::async_write(Socket, Streambuf,
                                       [this, self](boost::system::error_code ec, std::size_t)
                                       {
                                           std::cout &lt;&lt; "Oh, handled" &lt;&lt; std::endl;
                                           if (!ec)
                                           {
                                               // Initiate graceful connection closure.
                                               boost::system::error_code ignored_ec;
                                               Socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both,
                                                                ignored_ec);
                                           }
                                           if (ec != boost::asio::error::operation_aborted)
                                           {
                                               ConnectionManager.Stop(shared_from_this());
                                           }
                                       });
          }
  </code></pre>
  
  <p>What I'm doing wrong?</p>