*BSD News Article 28640


Return to BSD News archive

Xref: sserve comp.unix.programmer:15862 comp.unix.bsd:13637
Newsgroups: comp.unix.programmer,comp.unix.bsd
Path: sserve!newshost.anu.edu.au!munnari.oz.au!mel.dit.csiro.au!its.csiro.au!dmssyd.syd.dms.CSIRO.AU!metro!news.cs.su.oz.au!harbinger.cc.monash.edu.au!msuinfo!agate!ihnp4.ucsd.edu!usc!elroy.jpl.nasa.gov!netline-fddi.jpl.nasa.gov!nntp-server.caltech.edu!news.claremont.edu!kaiwan.com!wetware!spunky.RedBrick.COM!psinntp!psinntp!lehman.com!newshost!aajackso
From: aajackso@shadow.lehman.com (Aaron Jackson)
Subject: Re: Detecting dead client in BSD socket
In-Reply-To: leed@il.us.swissbank.com's message of Thu, 3 Mar 1994 15:48:52 GMT
Message-ID: <AAJACKSO.94Mar17181700@shadow.lehman.com>
Sender: news@lehman.com (News)
Nntp-Posting-Host: shadow
Organization: Lehman Brothers
References: <1994Mar3.154852.24090@il.us.swissbank.com>
Date: Thu, 17 Mar 1994 23:17:00 GMT
Lines: 22


>   Is there a way to determine, from the server side, whether a client has
>   closed its end of the connection in a BSD socket?  If the server attempts
>   a write to the dead client, SIGPIPE is received, and that works if
>   communication is steady and regular, but I'm wondering if there's a way
>   to determine client death/closure at an arbitrary moment.

If you are selecting or polling you will select will set the read bit
for the fd in question.  When you attempt to read it, it will return 0
bytes except under SysV.. BSD and POSIX with regards to non-blocking
I/O ensure that you will get bytes == -1 if there is a problem.. I
have yet to see read return 0 bytes unless an interrupt has occurred.
Hence, if your function which reads (many people write separate
routines to handle non-blocking I/O) returns 0 bytes read your
connection is probably dead.  Check errno for more details.

>   If this is a FAQ, feel free to refer me to it, or any in-print books for
>   that matter.

I wish there was a FAQ.

--