D. J. Bernstein
UNIX

Non-blocking I/O

UNIX kernel designers should provide sys/nonblock.h with nonblock_read() and nonblock_write() syscalls that don't block (and that don't generate SIGPIPE).

Adding nonblock_read() and nonblock_write() would save a considerable amount of time and effort in typical select/poll libraries such as my io library. It would eliminate bugs in quite a few programs that don't go to the same amount of effort.

Here are the alternatives to nonblock_read() and nonblock_write():

Here's what I'm doing now:

  1. Call read() or write() without further ado if the descriptor was originally provided in O_NONBLOCK mode or refers to a regular file. (Of course, it's possible that somebody subsequently turned O_NONBLOCK off; every program relying on O_NONBLOCK is taking this risk.)
  2. Use poll(), if it's available and functioning, to check whether the descriptor is ready.
  3. Set an interval timer.
  4. Call read() or write().
  5. Turn the interval timer off.
I'd much rather just call nonblock_read() or nonblock_write().