Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.programmer Subject: Re: Using select on FIFO's Message-ID: <1965:Jun309:17:2191@kramden.acf.nyu.edu> Date: 3 Jun 91 09:17:21 GMT References: Organization: IR Lines: 24 In article Bjorn.Larsen@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