Flow control in TCP
Suppose host A is transmitting data to host B. When this starts up host B will reserve some amount of memory to buffer unprocessed packages. Lets say it can fit RcvBuffer
bytes. Then it keeps track of LastByteRead
and LastByteRecieved
.
When returning an acknowledgement message to host A for a segment it populates the window field with RcvBuffer - [LastByteRecieved - LastByteRead]
. This informs host A how much buffer host B has left.
Host A will use this as one input to its Transmission control.
What if the window size is 0?
If the window size is 0 on the last Acknowledgement message then we could have a deadlock if host B doesn’t want to send anything to host A. It will process its messages but never send another ACK message to host A to tell it, it has more buffer available. To solve this problem host A will periodically send host B a single byte of data. Then it gets the new buffer size in the ACK message.