(Linux 3.0, x86_64)
If I stop calling recv(2) for a while on a connected tcp socket, and the other host keeps sending data, than presumably this data is received and buffered by the kernel, so the next time I call recv it will return quickly with all the waiting data.
My question is how big is this receive buffer, and how does it work? Are there any relevant kernel or socket settings I can use to tune its behavior? What does the tcp stack do when it fills up?
The receive buffer can be changed with
setsockopt(SO_RCVBUF). The default size is controlled by the tcp_rmem sysctl. If the buffer fills up, the stack will stop extending the receive window it offers to the other side, forcing the other size to stop sending data until there’s space in the buffer.