stream socket

Daniel Hartmeier daniel at benzedrine.cx
Thu Dec 23 15:00:19 UTC 2010


On Thu, Dec 23, 2010 at 05:47:14PM +0330, Mohammad Hedayati wrote:

> Suppose we've created a stream socket between two nodes. What happens
> if you write large chunks of data into the socket but the other pair
> doesn't read that for presumably long time?! Does the connection fail
> or data is missed?!

TCP includes flow control, through the advertised receive window[1].
When the peer stops reading, its receive buffer will fill up, closing
the receive window, until it reaches zero. At that point, the sender's
TCP/IP stack cannot send any further segments.

The sender has a send buffer (setsockopt(SO_SNDBUF),
net.inet.tcp.sendbuf_max), and the sender process will be able to
write until that is full. At that point, further writes will either
block or fail with EAGAIN. No data is missed, assuming the sender
process correctly handles this case (or simply blocks).

As long as the receiver is acknowledging but keeps a zero sized window,
the connection remains open, there is no timeout.

HTH,
Daniel

[1] http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Flow_control
[2] http://www.faqs.org/rfcs/rfc1122.html, 4.2.2.17 Probing Zero Windows


More information about the freebsd-net mailing list