A slight variation on this SO question.
Say the receiver expects packets to be at most 100 bytes. Say at time X there are actually 100 bytes available in the buffer, but for reasons the receiver only determines it needs to read 75 of those.
What happens with data not read from a socket?
Example:
Using flag MSG_PEEK (see here) the receiver determines that there is a full valid reply of 75 bytes in the buffer. The remaining 25 bytes must be the start of a next packet.
The receiver elects to remove only 75 bytes (i.e. ::recv() without the MSG_PEEK flag) from the buffer, leaving 25 bytes unread/unmoved in the buffer.
Say the receiver expects packets to be at most 100 bytes.Wrong assumption. There are no packets in TCP; it is a stream of bytes. (and: fragmentation is unrelated) And : these 25 bytes have not been recieved yet, so the cannot be in the buffer.