title: C - websocket - recv reads more than payload length
body: <p>I am building a websocket server in C. Right now it is following the rfc6455 specification and I have managed to get as far as implementing a chat protocol, such that connected clients
  can send messages to each other. To test the strength of my server I ran a piece of javascript to test if it could handle several messages from the same client per second:</p>
  
  <pre><code>i = ''; a = 0; t = setInterval('a++; i += "...................................................................................................."; doSend(a + i);', 20);
  </code></pre>
  
  <p>What the code above does is send a message each 20 ms. Furthermore the message that is sent, is 100 bytes larger for every message. The server manage to get the messages and send it to the connected clients the first 360 times, but then something weird happened.</p>
  
  <p>For every message the server receives, it takes the payload length of it, which for message 360 would be 360*100+3 = 36003. This value is given in the first part of the message and so we rely on that the message will actually be 36003 bytes long. </p>
  
  <p>I use the function recv to receive data from the socket connection and right now I have a buffer size of 8192 bytes. When I receive a message larger than my buffer size, I simply call recv once again until the whole message is received. The weird thing is that when I receive message number 360, I should read the buffer 5 times (5*8192 > 40000) to receive the whole message. Instead of my read number 5 being 3235 bytes (36003-(4*8192)) the recv function returns a full buffer aka. 8192 bytes. Does any have a clue about what is going on?</p>