Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Dec 2010 16:00:16 +0100
From:      Daniel Hartmeier <daniel@benzedrine.cx>
To:        Mohammad Hedayati <hedayati.mo@gmail.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: stream socket
Message-ID:  <20101223150016.GA10213@insomnia.benzedrine.cx>
In-Reply-To: <AANLkTimceAk2LAJRHDUKKOR_cGMTAN--E%2BXycR=v5XV-@mail.gmail.com>
References:  <AANLkTimceAk2LAJRHDUKKOR_cGMTAN--E%2BXycR=v5XV-@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20101223150016.GA10213>