*BSD News Article 60782


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.rmit.EDU.AU!news.unimelb.EDU.AU!munnari.OZ.AU!news.hawaii.edu!ames!usenet.kornet.nm.kr!news.kreonet.re.kr!usenet.seri.re.kr!news.cais.net!primus.ac.net!news.serv.net!solaris.cc.vt.edu!news.mathworks.com!news.kei.com!nntp.coast.net!news00.sunet.se!sunic!news99.sunet.se!nntp-trd.UNINETT.no!due.unit.no!pentagram.troll.no!nobody
From: Arnt Gulbrandsen <agulbra@troll.no>
Newsgroups: comp.unix.bsd.freebsd.misc,comp.os.linux.development.apps
Subject: Re: Checking for a closed socket connection
Date: 29 Jan 1996 12:19:27 +0100
Organization: Troll Tech AS, fax +47 22646949
Lines: 33
Sender: agulbra@pentagram.troll.no
	-0000
Message-ID: <d6wag372qps.fsf@pentagram.troll.no>
References: <NEWTNews.822505959.29723.jalvarez@sundev.uno.com>
	<4e7l8n$50f@charm.il.ft.hse.nl> <4effu2$ega@phoenix.ea4els.ampr.org>
NNTP-Posting-Host: pentagram.troll.no
X-Newsreader: Gnus v5.0.8
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:13325 comp.os.linux.development.apps:11668

sjmudd@phoenix.ea4els.ampr.org (Simon J Mudd)
> Robert Klep (robert@il.ft.hse.nl) wrote:
> > jalvarez@uno.com:
> >  >Is there a simple way to test a socket descriptor for a closed
> >  >connection (e.g. if the connection to the other side was lost
> >  >and is no longer valid) ?
> 
> > read() to/write() from it and see if the function returns a -1 :)
> 
> is it acceptable therefore to read 0 bytes, or write 0 bytes?

The TCP protocol allows packets with 0 bytes payload, but I would not
recommend using it at the application layer - you're staking too much
on the kernel implementation.

If you need real keepalive, and the two-hour default of
setsockopt(SO_KEEPALIVE) isn't enough, you need to design it into your
protocol.  Anything else is going to break on one TCP stack or
another; there are so many of them, all slightly different.

SMTP has NOOP, which tells the server to send a "250 OK" and do
nothing else.  I recommend that you do something similar.

         NOOP (NOOP)

            This command does not affect any parameters or previously
            entered commands.  It specifies no action other than that
            the receiver send an OK reply.

            This command has no effect on any of the reverse-path
            buffer, the forward-path buffer, or the mail data buffer.

--Arnt