title: What's the meaning of boost::asio::placeholders::bytes_transferred
body: <p>What is the meaning of <code>boost::asio::placeholders::bytes_transferred</code> in <code>async_read_until()</code>? In the callback function it returns smaller value, than <code>streambuf.size()</code>. <code>streambuf</code> was clear before the callback. To sum up,...<code>bytes_transferred</code> is not the actual number of bytes went through the socket, but less. Do I have misunderstood all of this, or what?</p>
  
  <p><strong>EDIT:</strong> I read the following protocol from a socket:</p>
  
  <blockquote>
    <p><code>Y43,72,0,,91009802000000603=0000000000000000000</code></p>
  </blockquote>
  
  <p><code>"Y43,"</code> - is the header.<br>
  <code>"Y"</code> - is message type.<br>
  <code>"43"</code> - additional bytes to read<br>
  <code>","</code> - delimiter. The header is the until the first "," encountered.</p>
  
  <p>My code is for reading is like:</p>
  
  <pre><code>void handle_write(const boost::system::error_code&amp; error,
                    size_t bytes_transferred)
  {
      if (!error)
      {
          boost::asio::async_read_until(
              socket_,
              inputStreamBuffer_,
              ',',
              boost::bind(
                  &amp;client::handle_read1, this,
                  boost::asio::placeholders::error,
                  boost::asio::placeholders::bytes_transferred
              )
          );
      }
      else
      {
          std::cout &lt;&lt; "Write failed: " &lt;&lt; error &lt;&lt; "\n";
      }
  }
  
  void handle_read1(const boost::system::error_code&amp; error,
                    size_t bytes_transferred)
  {
      cout &lt;&lt; "bytes_transferred=" &lt;&lt; bytes_transferred &lt;&lt; endl;
  
      if (!error)
      {
          cout &lt;&lt; "0 size=" &lt;&lt; inputStreamBuffer_.size() &lt;&lt; endl;
          istream is(&amp;inputStreamBuffer_);
          char c[1000];
          is.read(c,bytes_transferred);
          c[bytes_transferred]=0;
          for (int i=0;i&lt;bytes_transferred;++i)
          {
              cout &lt;&lt; dec &lt;&lt; "c[" &lt;&lt; i &lt;&lt; "]=" &lt;&lt; c[i] &lt;&lt; " hex=" &lt;&lt; hex &lt;&lt; static_cast&lt;int&gt;(c[i]) &lt;&lt; "#" &lt;&lt; endl;
          }
      }
      else
      {
          std::cout &lt;&lt; "Read failed: " &lt;&lt; error &lt;&lt; "\n";
      }
  }
  </code></pre>
  
  <p>For stream sent from the other side:</p>
  
  <blockquote>
    <p><code>Y43,71,0,,91009802000000595=0000000000000000000</code></p>
  </blockquote>
  
  <p>Some times, I read this:</p>
  
  <blockquote>
    <p><code>bytes_transferred=4</code><br>
    <code>0 size=47</code><br>
    <code>c[0]=Y hex=59#</code><br>
    <code>c[1]=4 hex=34#</code><br>
    <code>c[2]=3 hex=33#</code><br>
    <code>c[3]=, hex=2c#</code></p>
  </blockquote>
  
  <p>For stream sent from the other side:</p>
  
  <blockquote>
    <p><code>Y43,72,0,,91009802000000603=0000000000000000000</code></p>
  </blockquote>
  
  <p>But other times, I read this:</p>
  
  <blockquote>
    <p><code>bytes_transferred=7</code><br>
    <code>0 size=47</code><br>
    <code>c[0]= hex=0#</code><br>
    <code>c[1]= hex=0#</code><br>
    <code>c[2]= hex=0#</code><br>
    <code>c[3]= hex=0#</code><br>
    <code>c[4]=7 hex=37#</code><br>
    <code>c[5]=2 hex=32#</code><br>
    <code>c[6]=, hex=2c#</code></p>
  </blockquote>
  
  <p>The socket is secured with SSL, and the client and server apps are slightly modified examples from boost_asio/example/ssl/* .</p>
  
  <p>In the second example I loose the entire header :(</p>