Subject: Re: select(2) question...
To: None <kenh@entropic.com>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: tech-userlevel
Date: 12/14/1994 13:10:04
> According to "Advanced Programming in the Unix Environment", by
> Richard Stevens, an exception condition is triggered by two things:

> - Out of band data arriving on a networking connection
> - Certain conditions occuring on a pseudo-tty that has been placed
>   into packet mode.

UTSLing reveals that any device driver is empowered to signal
exceptional conditions in its select routine.

> If I'm not mistaken, an end of file is signalled by a zero-length
> read.

Mostly true.  Zero-length reads can also indicate no data available in
nonblocking mode.

> If select says the data is available for reading, and read() returns
> zero, then the file is closed.

No - just that EOF has been reached.  If a non-open file descriptor
number is passed to select(), it returns EBADF.

Note that it is also possible for select() to indicate reading is
possible but for a read to return zero if:
	- Another process also holds a copy of that file descriptor
	  (eg, inherited via fork).
	- The fd is nonblocking.
	- The other process consumed all available data between the
	  time select() returned and the time read() was called.

By the way, this strikes me as off-topic for tech-userlevel; it's
actually about syscalls in general and the guts of select().  Perhaps
tech-userlevel should be removed from the cc list?

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu