From owner-freebsd-net@FreeBSD.ORG Mon Jun 25 16:52:56 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7977016A400 for ; Mon, 25 Jun 2007 16:52:56 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail08.syd.optusnet.com.au (mail08.syd.optusnet.com.au [211.29.132.189]) by mx1.freebsd.org (Postfix) with ESMTP id 0172013C469 for ; Mon, 25 Jun 2007 16:52:55 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from besplex.bde.org (c220-239-235-248.carlnfd3.nsw.optusnet.com.au [220.239.235.248]) by mail08.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id l5PGqjcL014450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 26 Jun 2007 02:52:50 +1000 Date: Tue, 26 Jun 2007 02:52:45 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Julian Elischer In-Reply-To: <467C727D.4060703@elischer.org> Message-ID: <20070626023944.M82078@besplex.bde.org> References: <467C727D.4060703@elischer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: FreeBSD Net Subject: Re: [6.x] problem with AIO, non-blocking sockets on freebSD and IE7 on windows. 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: Mon, 25 Jun 2007 16:52:56 -0000 On Fri, 22 Jun 2007, Julian Elischer wrote: > If one has an event-driven process that accepts tcp connections, one needs to > set eh non-blocking socket option and use kqueue or similar to schedule work. > > This is ok for data transfers, however when it comes to the close() call > there is a problem. The problem in in the following code in so_close() > > > if (so->so_options & SO_LINGER) { > if ((so->so_state & SS_ISDISCONNECTING) && > (so->so_state & SS_NBIO)) > goto drop; > ... > drop: > [ continues on to destroy socket ] > > > because SS_NBIO is set, the socket acts as if SO_LINGER was set, with a > timeout of 0. > the result of this, is the following behaviour: [ patckets in flight get lost ] This seems to be the correct behaviour. The application doesn't care about its data and/or wants to close the descriptor without blocking, so it doesn't turn off the blocking flag and/or wait for i/o to complete (so that it can see if the i/o actually worked) before calling close(). I implemented this behaviour for tty drivers in FreeBSD. Old BSD tty drivers didn't check the nonblocking flag and didn't have a timeout, so close() on tty devices tended to hang forever (normally at long weekends) even for closes that should have been nonblocking. Bruce