From owner-freebsd-net@FreeBSD.ORG Thu Dec 23 15:00:19 2010 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D3DDA10656A5 for ; Thu, 23 Dec 2010 15:00:19 +0000 (UTC) (envelope-from dhartmei@insomnia.benzedrine.cx) Received: from insomnia.benzedrine.cx (106-30.3-213.fix.bluewin.ch [213.3.30.106]) by mx1.freebsd.org (Postfix) with ESMTP id 692518FC1F for ; Thu, 23 Dec 2010 15:00:16 +0000 (UTC) Received: from insomnia.benzedrine.cx (localhost.benzedrine.cx [127.0.0.1]) by insomnia.benzedrine.cx (8.14.1/8.13.4) with ESMTP id oBNF0GOH019189 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Thu, 23 Dec 2010 16:00:16 +0100 (MET) Received: (from dhartmei@localhost) by insomnia.benzedrine.cx (8.14.1/8.12.10/Submit) id oBNF0GHs007563; Thu, 23 Dec 2010 16:00:16 +0100 (MET) Date: Thu, 23 Dec 2010 16:00:16 +0100 From: Daniel Hartmeier To: Mohammad Hedayati Message-ID: <20101223150016.GA10213@insomnia.benzedrine.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.12-2006-07-14 Cc: freebsd-net@freebsd.org Subject: Re: stream socket X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Dec 2010 15:00:19 -0000 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