title: Why is boost::asio::read buffer data size lesser than read size?
body: <p>I have a simple file transfer application, which transfers 4096 bytes per write from the client. In the server end, I am using the following call read</p>
  
  <p>tempLen = boost::asio::read(l_Socket, boost::asio::buffer(buf, bufSize), boost::asio::transfer_all(), error);</p>
  
  <p>The templen is 1440 bytes, but when I read the buf, it is only 11 bytes. Copy pasting the server code below. I have tried both socket.read_some and asio::read - both end in same result. Can someone explain what am I doing wrong here?</p>
  
  <pre><code>//boost::array&lt;char, 4096&gt; buf;
  char* buf = new char[4096];
  char* bigBuffer = new char[2097152];
  std::string strBuffer;
  
  strBuffer.clear();
  
  for (;;) // Loop for the whole file length
  {
  
      boost::asio::read_until(l_Socket, request_buf, "\n\n");
      std::istream request_stream(&amp;request_buf);
      request_stream &gt;&gt; bufSize;
      std::cout&lt;&lt; "Size of the Compressed data transfer:" &lt;&lt; bufSize &lt;&lt; "\n";
  
      // Clear the stream
      request_stream.clear();
      memset(bigBuffer, 0, 2097152);
      memset(buf, 0, 4096);
  
      if(bufSize == 0)
          break;
  
      size_t len = 0, prevLen = 0, tempLen = 0;
  
      try{
  
          //tempLen = l_Socket.read_some(boost::asio::buffer(buf, bufSize), error);
          tempLen = boost::asio::read(l_Socket, boost::asio::buffer(buf, bufSize), boost::asio::transfer_all(), error);
          std::cout &lt;&lt; "Length from read: " &lt;&lt; tempLen &lt;&lt; " Buffer Size: " &lt;&lt; bufSize &lt;&lt; std::endl;
          prevLen = len;
  
          len += tempLen;
  
      }
      catch (boost::exception&amp; e)
      {
           std::cerr &lt;&lt; diagnostic_information(e);
      }.....}
  </code></pre>
  
  <p>Edit: </p>
  
  <p>Just checked this problem is happening only when I send the data compressed with the following function at the client.</p>
  
  <pre><code>    std::string CClient::Compress(const char* data, unsigned int* dataLen)
  {
      std::stringstream compressed;
      std::stringstream decompressed;
      std::cout &lt;&lt; "From Compress Function: " &lt;&lt; " Size of Decompressed Data: " &lt;&lt; strlen(data) &lt;&lt; std::endl;
      decompressed &lt;&lt; data;
      boost::iostreams::filtering_streambuf&lt;boost::iostreams::input&gt; out;
      out.push(boost::iostreams::zlib_compressor());
      out.push(decompressed);
      boost::iostreams::copy(out, compressed);
      *dataLen = compressed.str().size();
      return compressed.str();
  }
  
  std::string CClient::DeCompress(const std::string&amp; data)
  {
      std::stringstream compressed;
      std::stringstream decompressed;
      compressed &lt;&lt; data;
      boost::iostreams::filtering_streambuf&lt;boost::iostreams::input&gt; in;
      in.push(boost::iostreams::zlib_decompressor());
      in.push(compressed);
      boost::iostreams::copy(in, decompressed);
      std::cout &lt;&lt; "Decompressed Data: " &lt;&lt; decompressed.str().c_str() &lt;&lt; std::endl;
      return decompressed.str();
  }
  </code></pre>
  
  <p>When I decompress the data at "the client" itself after compression(before sending), the data is getting printed properly. But when I read the data after receiving at the server, I am facing this problem.</p>