Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Jun 2004 16:20:24 -1000 (HST)
From:      Julian Cowley <julian@tikitechnologies.com>
To:        freebsd-questions@FreeBSD.org
Subject:   SO_LINGER on socket with non-blocking I/O
Message-ID:  <Pine.LNX.4.58.0406091601190.24191@taurus.cesta.com>

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



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