*BSD News Article 60936


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.cs.su.oz.au!inferno.mpx.com.au!news.mel.aone.net.au!imci4!newsfeed.internetmci.com!swrinde!tank.news.pipex.net!pipex!dish.news.pipex.net!pipex!tube.news.pipex.net!pipex!lade.news.pipex.net!pipex!news00.sunet.se!sunic!news99.sunet.se!nntp-trd.UNINETT.no!Norway.EU.net!oslonett.no!sn.no!newsfeed.tip.net!oden.exmandato.se!newsfeed1.telia.com!d1o3.telia.com!usenet
From: b.jonsson@vaxjo.mail.telia.com (Borje Jonsson)
Newsgroups: comp.unix.bsd.freebsd.misc,comp.os.linux.development.apps,comp.unix.programmer
Subject: Re: Checking for a closed socket connection
Date: 1 Feb 1996 19:58:17 GMT
Organization: Telia Internet Services
Lines: 46
Message-ID: <4er60p$ckr@d1o3.telia.com>
References: <NEWTNews.822505959.29723.jalvarez@sundev.uno.com> <1996Jan25.135629.7187@brutus.tlug.org>
NNTP-Posting-Host: t14o2p5.telia.com
Mime-Version: 1.0
X-Newsreader: WinVN 0.93.14
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:13453 comp.os.linux.development.apps:11820 comp.unix.programmer:33793

In article <1996Jan25.135629.7187@brutus.tlug.org>, vic@brutus.tlug.org 
says...
>
>jalvarez@uno.com wrote:
>
>: 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) ?
>
>Though I've heard that read() and write() should return -1 in this 
condition,
>it is my experience with linux that read() and write() return 0.  I have 
had
>some success with checking for a return of <= 0.  If I persist in my 
reads
>and writes, I eventually get an EPIPE error with a -1 return.
>
>According to previous posts I have read, this is valid.  Some other 
systems
>will return ECONNRESET, or EINVAL in errno.
>
>Is checking for the 0 return from read()/write() a bad idea?  Can this 
happen
>under normal conditions?
>
.
.
.
>
>Thanks,
>  Vic.



I recently made a small program that communicate between a Linux and
an AIX box. A server process waits for connect from a client and then
read data from client and write back answers. When the client is forced
to disconnect (typing ctrl-C) the read call on server process returns -1
and errno ECONNRESET or 0 and errno 0 on the AIX box.The same is true
for Linux.
The problem is that there is no apparent way to tell when -1 and 
ECONNRESET is returned or when 0 and errno 0 is returned.

regards
Borje Jonsson