[comp.unix.wizards] nonblocking I/O techniques for System V

tr@madeleine (tom reingold) (08/23/89)

What's the technique for nonblocking I/O for System V.  In BSD, you use
select() which is very convenient and elegant.  What's the equivalent.
I think I've heard that it requires several function calls.

Tom Reingold                   |INTERNET:       tr@bellcore.com
Bellcore                       |UUCP:           bellcore!tr
444 Hoes La room 1H217         |PHONE:          (201) 699-7058 [work],
Piscataway, NJ 08854-4182      |                (201) 287-2345 [home]

norm@oglvee.UUCP (Norman Joseph) (08/24/89)

From article <17450@bellcore.bellcore.com>, by tr@madeleine (tom reingold):
> What's the technique for nonblocking I/O for System V.  In BSD, you use
> select() which is very convenient and elegant.  What's the equivalent.
> I think I've heard that it requires several function calls.

See your system's manual page for the open() system call, and look for the
O_NDELAY flag.  According to Rochkind in _Advanced_UNIX_Programming_,
Sec. 2.6:

        When opening pipes, FIFOs, and communication-line special
        files, this flag determines whether open waits or returns
        immediately.  Subsequent reads and writes are also affected.
        [...]  O_NDELAY has no effect on ordinary files and directories.

The drawback is that, if no data is waiting, a read() will return a zero
count, just as if you had hit ^D.

You may also consider supplementing your library with Rochkind's book
(ISBN 0-13-011800-1), which contains a wealth of information on programming
with UNIX system calls.

Disclaimer: NOT a stockholder in Prentice-Hall, just a satisfied customer.
-- 
Norm Joseph - Oglevee Computer System, Inc.
  UUCP: ...!{pitt,cgh}!amanue!oglvee!norm
    /* you are not expected to understand this */