title: How can I write a file to a socket using the 'chunked' HTTP Transfer-Protocol in boost::asio?
body: <p>So working off of the <a href="http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/examples.html">boost HTTP Server 3 example</a>, I want to modify connection::handle_read to support sending a body along with the message. However, the method for doing this is not apparent to me.  I want to write something like:</p>
  
  <pre><code>void connection::handle_read(const boost::system::error_code&amp; e,
      std::size_t bytes_transferred)
  {
      ...
   if (result)
      {     
        boost::asio::async_write(socket_, reply.to_buffers(),
            strand_.wrap(
              boost::bind(&amp;connection::write_body, shared_from_this(),
                boost::asio::placeholders::error)));
      }
  }
  
  void connection::write_body(const boost::system::error_code&amp; e)
  {
      boost::asio::async_write(socket_, body_stream_,
        strand_.wrap(
        boost::bind(&amp;connection::handle_write, shared_from_this(),
        boost::asio::placeholders::error)));
  }
  </code></pre>
  
  <p>where <code>body_stream_</code> is an <code>asio::windows::stream_handle</code>. </p>
  
  <p>But this approach doesn't handle the http chunking at all (all that means is the size of the chunk is sent before each chunk). What is the best way to approach this problem?  Do I write my own wrapper for an ifstream that adheres to the requiresments of a <a href="http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/reference/ConstBufferSequence.html">boost const buffer</a>? Or try to simulate the effect of <code>async_write</code> with multiple calls to <code>async_write_some</code> in a loop?  I should mention a requirement of the solution is that I never have the entire file in memory at any given time - only one or a few chunks. </p>
  
  <p>Very new to ASIO and sockets, any advice is appreciated!</p>