title: non-blocking udp socket programming in C: what do I get?
body: <p>I have a problem in understanding what recv()/recvfrom() return from an non-blockig UDP socket.</p>
  
  <p>A bit more specific and compared to TCP (please correct me if I'm wrong):</p>
  
  <ul>
  <li><p>A blocking socket (either TCP or UDP) won't return from a recv() until there is some data in the buffer. This could be some number of bytes (TCP) or a complete datagram (UDP).</p></li>
  <li><p>A non-blocking TCP socket either returns EWOULDBLOCK (linux) / WSAEWOULDBLOCK (windows) or the bytes that are currently in the buffer. As TCP data is a stream it doesn't matter how many bytes are returned.</p></li>
  </ul>
  
  <p>Now the question:</p>
  
  <ul>
  <li>A non-blocking UDP socket also returns WOULDBLOCK (linux) / WSAEWOULDBLOCK (windows) if there is no data available. But if there is data availabe, does a non-blocking UDP socket return just some bytes, which could mean you only get half of a datagram OR does an UDP socket always return complete datagrams??</li>
  </ul>
  
  <p>Edit:</p>
  
  <p>What I mean with "half of a datagram" is: what happens if I call recv() in just the moment when the socket is currently receiving a datagram. In that moment there are some bytes in the buffer but the datagram isn't complete yet.</p>
  
  <p>Your explanations and comments are appreciated. Thanks!</p>