title: C/C++ sockets and a non-blocking recv()
body: <p>I'm having a problem where calling recv() system call does not block. I have a client-server structure setup at the moment, and the problem I am having is I send the server one message, while the server is set up so that it's something like:</p>
  
  <pre><code>while (1) {
     char buf[1024];
     recv(fd, buf, sizeof(buf), flags);
     processMsg(buf);
  }
  </code></pre>
  
  <p>It receives the first message correctly, but the recv() does not block and "receives" trash data which is not what is desired. I'd like to react to messages only when they are sent. Can anyone advise? </p>