title: TCP: What happens when client connects, sends data and disconnects before accept
body: <p>I'm testing some code in C and I've found strange behaviour with TCP socket calls. </p>
  
  <ol>
  <li><p>I've defined one listening thread which accepts clients synchronously and after accepting the client it process it in a for loop until it disconnects. Thus only one client at a time is handled. So I call <code>accept</code> in a loop and then <code>recv</code> in an inner loop until received an empty buffer.</p></li>
  <li><p>I fire 5 threads with clients, I call <code>connect</code>, <code>send</code> and finally <code>close</code></p></li>
  <li><p>I get no error in any call. Everything seems to be fine.</p></li>
  </ol>
  
  <p>However when I print received message on the server side it turns out that only the first client got through to the server, i.e. <code>accept</code> never fires on other clients.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Shouldn't <code>connect</code> wait until server calls <code>accept</code>? Or is the kernel layer taking care of buffering under the hood?</li>
  <li>If it's not the case then shouldn't the server be able to accept the socket anyway, even if it is in a disconnected state? I mean is it expected to lose all the incoming data?</li>
  <li>Or should I assume that there's a bug in my code?</li>
  </ol>