From owner-freebsd-questions@FreeBSD.ORG Thu Jun 10 02:20:25 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 18B1216A4CE for ; Thu, 10 Jun 2004 02:20:24 +0000 (GMT) Received: from lima.cesta.com (lima.cesta.com [64.65.85.11]) by mx1.FreeBSD.org (Postfix) with ESMTP id B244743D1F for ; Thu, 10 Jun 2004 02:20:24 +0000 (GMT) (envelope-from julian@tikitechnologies.com) Received: from lima.cesta.com (lima.cesta.com [64.65.85.11]) by lima.cesta.com (Postfix) with ESMTP id 1DF1F53C0E2 for ; Wed, 9 Jun 2004 16:20:24 -1000 (HST) Date: Wed, 9 Jun 2004 16:20:24 -1000 (HST) From: Julian Cowley X-X-Sender: julian@taurus.cesta.com To: freebsd-questions@FreeBSD.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: SO_LINGER on socket with non-blocking I/O X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jun 2004 02:20:25 -0000 Hello FreeBSD'ers... I've been developing an application that attempts to send data from one host to another via TCP. The intent is for the data transfer to be as reliable as possible, and to log whenever it detects that it has lost data (this is for a reliable syslog protocol, if you're wondering). Because my application doesn't (yet) have application-level acknowledgments, it has to depend on TCP to make sure the data gets through reliably. When closing the socket, I want to make sure that the remaining data got through to the other end (or otherwise log something if it didn't). I've set SO_LINGER on the socket for this purpose, but one caveat is that I also have the socket in non-blocking mode. My question is, what is the behavior of close() on a socket in non-blocking mode when SO_LINGER is set (to a non-zero time)? There seems to be two, possibly three, possibilities according to some web searches I've done: 1) the close() call immediately returns with an EWOULDBLOCK (EAGAIN) error. 2) the call blocks anyway regardless of the non-blocking mode setting. 3) the call returns immediately after the connection is forcibly reset, possibly losing any queued data that was to be sent. I'm pretty sure the third possibility only happens when SO_LINGER is set with a linger time of 0 seconds. Any ideas? It would be really nice if the man pages could document this particular case. -- In the Year 2000 (tm)... "I will convert to Judasism and change my trademark Fa Shizzle My Nizzle to Sheiztle Fa Zeitzel." -- Snoop Dog