Henrik Nordstrom wrote:

> > If the descriptor is non-blocking (O_NONBLOCK), read() will return -1
> > and set errno to EAGAIN. You don't need to check whether data is
> > available in order to prevent blocking.
> 
> If you have no problem with the program using 100% CPU while it waits
> for data to arrive it is fine with me. I prefer to have programs wait
> until there is data available on at least one of the filedescriptors it
> uses if it has nothing else to do at the moment.
> 
> Most uses of non-blocking I/O is when a singre process wants to handle
> multiple connections at the same time, and then is it not very nice to
> constantly call read() on every open filedescriptor to see if any data
> has arrived yet.

Sure, but there's no point in using non-blocking I/O in this case. If
you use select() to wait until the descriptor is ready, then the
subsequent read() or write() is guaranteed not to block.

Non-blocking I/O is useful primarily when it is interleaved with
something else, e.g. computation or blocking I/O.

There is seldom any point in using both select() and O_NONBLOCK. In
fact some implementations of select() (although Linux' doesn't appear
to be one of them) don't work correctly on non-blocking descriptors. 
In these cases, select() usually indicates that a read() or write()
won't block (so it will always be true for a non-blocking descriptor),
rather than indicating that the operation will `succeed'.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to