For all practical purposes you should view TCP receiving as composed of two independent processes:
- the OS receives the TCP data and ACKs it to the other side, storing it in an internal kernel buffer that's not accessible to your process
- when you
recv
or any equivalent system call, the OS copies the data from its internal buffers to your userspace buffer
Once TCP has received data that is in window and passes checksums and all, the other side cannot renege it. Which means it doesn't really matter if it sends the ACK before or after you read the data. Plus, the OS might need to ACK again (if the ACK is lost for example). Thus, the timing of ACKing data has nothing to do with you reading from the socket (the advertised window however, does).
The takeaway from this is that you doing recv
has no effect on the connection. You can view recv
as a fancy memcpy
from the socket buffer to your application buffer.