Using select on FIFO's

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Mon Jun 3 19:17:21 AEST 1991


In article <BLARSEN.91May30090732 at spider.uio.no> Bjorn.Larsen at usit.uio.no writes:
> Originally, the program opened the FIFO's with O_NONBLOCK, and tried
> to read them occationally. It turns out that select() on such a file
> descriptor returns immediately, indicating that the fd was ready.  In
> a sense, that is true -- the fd is ready so far that I can take a
> read() on it without blocking. But what I expected select() to do was
> to tell me wether there was data on the FIFO, not wether it is
> possible to issue a read() on the fd.

select() normally tells you whether the I/O would block *if* the
descriptor were blocking. Unfortunately, ``blocking'' has one meaning in
System V, one meaning in BSD, two slightly different meanings in SunOS,
and yet another slightly different meaning in POSIX---and select() only
respects the BSD meaning. Don't expect select() to work properly if you
combine different nonblocking mechanisms.

Since you're using select(), you might as well not bother with NONBLOCK.
Just make sure to select() before every I/O operation. (Beware that if
there are multiple readers or writers on a pipe, select() can't
guarantee that the I/O won't block a moment later. In that case you
also have to set nonblocking before each I/O and unset it before
select(). It's at times like this that I wish for VMS I/O.)

---Dan



More information about the Comp.unix.programmer mailing list