Subject: Re: Sensing a disconnected socket
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: current-users
Date: 06/26/1997 12:44:19
>>> I was using fgetc(stdout), [without setting feof or ferror]
>> That's no surprise.  fgetc on an output-only stream [...]
> 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.

You're confusing two things: stdout, which is a stdio stream and is
output-only, and file descriptor 1, which in traditionally used for
output but in your case is bidirectional.  select() is telling you fd 1
is readable, but stdout is still an output-only stream.

You may want to use fdopen to open a read stream on fd 1, or perhaps
just use read().

					der Mouse

		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B