title: About recv and the read buffer - C Berkeley Sockets
body: <p>I am using berkeley sockets and TCP (SOCK_STREAM sockets).</p>
  
  <p>The process is:</p>
  
  <ol>
  <li>I connect to a remote address.</li>
  <li>I send a message to it.</li>
  <li>I receive a message from it.</li>
  </ol>
  
  <p>Imagine I am using the following buffer:</p>
  
  <pre><code>char recv_buffer[3000];
  recv(socket, recv_buffer, 3000, 0);
  </code></pre>
  
  <p>Questions are:</p>
  
  <ul>
  <li>How can I know if after calling recv first time the read buffer is empty or not? If it's not empty I would have to call recv again, but if I do that when it's empty I would have it blocking for much time.</li>
  <li>How can I know how many bytes I have readed into recv_buffer? I can't use strlen because the message I receive can contain null bytes.</li>
  </ul>
  
  <p>Thanks. </p>