title: read function's return value and the length of the buffer are not the same, C language, ubuntu 12.04
body: <p>In ubuntu 12.04, I want to write a concurrent server, which can receive http packets from my virtual machine, then forward the packets to the original destination of my VM. But when I'm reading the packets using read function in C language, sometimes <strong>the return value and the length of buffer are not the same</strong> (for example: rbyte=1024, strlen(buf)=62 ). I've checked errno and find that errno=0, which means no error with the read function. I think that these two variables should be exactly the same, but for my program, they are not. The following is part of my code:</p>
  
  <pre><code>char buf[1024];
  size_t rbyte = read(sFrom, buf, sizeof(buf) );
  cerr &lt;&lt; "length of buf: " &lt;&lt; strlen(buf) &lt;&lt; "\n";
  cerr &lt;&lt; "rbyte: " &lt;&lt; rbyte &lt;&lt; "\n";
  </code></pre>
  
  <p>I've read <a href="http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html" rel="nofollow">http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html</a> to get some clues, but still don't know the reason of this error.</p>
  
  <p>Does anyone know the reason?</p>