Subject: Re: Sensing a disconnected socket
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Rick Byers <rickb@iaw.on.ca>
List: current-users
Date: 06/26/1997 12:42:11
On Thu, 26 Jun 1997, der Mouse wrote:

> >>> Interestingly enough, ferror and feof both return 0 after EOF is
> >>> read (shouldn't one be true?).
> >> ferror and feof work on stdio streams.  select, read, and write work
> >> on file descriptors.  There is no stdio analog to select(); I can't
> >> even see one in the NetBSD extensions to standard stdio.  If you
> >> read EOF via read(), stdio won't know anything about it.
> > I was using fgetc(stdout), it returned -1, and ferror and feof both
> > return 0 afterwards.
> 
> That's no surprise.  fgetc on an output-only stream just returns EOF
> with errno set to EBADF, without setting either the EOF or error flags
> on the stream.  See __srefill() in /usr/src/lib/libc/stdio/refill.c.

Except in this case I don't think it is an output only stream.  The HTTP
server sets stdout of my CGI program to the HTTP socket.  I only do an
fgetc on it when select tells me there is data avialble for reading from
the socket (stdout).  It's not a big deal, just the indication that there
IS data available fro READING on stdout is enough of an indication that
the socket has been closed.

Thanks,	
	Rick

=========================================================================
Rick Byers                                      Internet Access Worldwide
rickb@iaw.on.ca                                System Admin, Tech Support
Welland, Ontario, Canada                                    (905)714-1400
http://www.iaw.on.ca/rickb/                         http://www.iaw.on.ca/