0

If I call recv(1024) on a connected, blocking, TCP socket, and there is no data in the receive buffer, the recv call blocks, waiting for data to arrive into the receive buffer.

I've read in several places that recv blocks until "some" data is in the buffer. How much is "some"? Is there a threshold? And is there a timeout if that threshold is not met (and more than zero bytes are available)?

If my application needs to receive 100 bytes and the first recv call blocks, what's stopping recv from returning one byte at a time as it arrives in the receive buffer in my application receive loop for the full 100 bytes?

  • 1
    `some` is one character or more. – wildplasser Apr 22 '20 at 23:38
  • The only thing that can stop `recv()` from returning one byte at a time is the `MSG_WAITALL` flag. And if the sender sends one byte at a time at long enough intervals, not even that. More usually you will get unwanted coalescing rather than unwanted splitting, but your application code has to be able to cope with both. – user207421 Apr 22 '20 at 23:54

0 Answers0