title: issues about using async_write right after async_read_until
body: <p>My code is as follows:</p>
  
  <pre><code>boost::asio::streambuf b1;
  
  boost::asio::async_read_until(upstream_socket_, b1, '@',
             boost::bind(&amp;bridge::handle_upstream_read, shared_from_this(),
             boost::asio::placeholders::error,
             boost::asio::placeholders::bytes_transferred));
  
  
  void handle_upstream1_read(const boost::system::error_code&amp; error,
                              const size_t&amp; bytes_transferred)
    {
       if (!error)
       {
  
         async_write(downstream_socket_,
            b2,
            boost::bind(&amp;bridge::handle_downstream_write,
            shared_from_this(),
            boost::asio::placeholders::error));  
       }
       else
          close();
    }
  </code></pre>
  
  <p>According to the documentation of async_read_until, <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/async_read_until/overload1.html" rel="nofollow">http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/async_read_until/overload1.html</a>, 
  After a successful async_read_until operation, the streambuf may contain additional data beyond the delimiter. An application will typically leave that data in the streambuf for a subsequent async_read_until operation to examine.</p>
  
  <p>I know that the streambuf may contain additional data beyond the delimiter, but, in my case, will it write those additional data (the data beyond the char'@') to the downstream_socket_ inside the async_write operation? Or will async_write function be smart enough not to write those additional data until the next time the handle_upstream1_read function is being called?</p>
  
  <p>According to the approaches in the documentation, the data in streambuf are stored in the istream first ( std::istream response_stream(&amp;streambuf); )
  and then put it into a string by using std::getline() funciton.</p>
  
  <p>Do I really need to store the streambuf in istream first and then convert it into a string and then convert it back to char arrary (so that I can send the char array to the downstream_socket_  ) instead of just using the async_write to write the data( up to but not including the delimter, '@' ) to the downstream_socket_ ?</p>
  
  <p>I prefer the second approach so that I don't need to make several conversion on the data. However, it seems that something is wrong when I tried the second approach. </p>
  
  <p>My ideal case is that:</p>
  
  <ol>
  <li>upstream_socket_ received xxxx@yyyy by using async_read_until</li>
  <li>xxxx@ is written to the downstream_socket_</li>
  <li>upstream_socket_ received zzzz@kkkk by using async_read_until</li>
  <li>yyyyzzzz@ is written to the downstream_socket_</li>
  </ol>
  
  <p>It seems that async_write operation still writes the data beyond the delimiter to the downstream_socket_. (but I am not 100% sure about this)</p>
  
  <p>I appreciate if anyone can provide a little help !</p>