Return to BSD News archive
Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msunews!news.gmi.edu!zombie.ncsc.mil!news.mathworks.com!newsfeed.internetmci.com!in1.uu.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: 26 Jan 1996 00:26:13 +0100 Organization: Troll Tech AS, fax +47 22646949 Lines: 15 Sender: agulbra@pentagram.troll.no Message-ID: <d6w20onluui.fsf@pentagram.troll.no> References: <NEWTNews.822505959.29723.jalvarez@sundev.uno.com> <4e7l8n$50f@charm.il.ft.hse.nl> NNTP-Posting-Host: pentagram.troll.no X-Newsreader: Gnus v5.0.8 Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:13166 comp.os.linux.development.apps:11531 robert@il.ft.hse.nl (Robert Klep) > 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 :) write() is unfortunate, of course. read() is better, unless your application can't store any read data until it _really_ wants to read. But you do have the option of using getpeername(), which should work nicely. --Arnt