non-blocking read
Geoff Kuenning
geoff at proper.UUCP
Tue Feb 7 20:33:34 AEST 1984
A request was made on the net for information on how to do a non-blocking
read from a terminal. Under 4BSD and UniSoft ports, the FIONREAD 'ioctl'
can be used to check for characters, albeit at a high cost in CPU time.
Other solutions have been posted to the net.
A related question is how to do asynchronous disk I/O for purposes of
double buffering. System V provides an open/fcntl option for non-blocking
(read asynchronous) I/O, but there is a *VERY* nasty catch: there is no
way to find out when the I/O is finished! This makes the non-blocking feature
pretty useless.
Indeed, when I examined the double-buffering code in "volcopy"
to find out how they did it, I discovered that they fork a copy of themselves
and then write "r" and "w" characters across pipes to synchronize the two
copies. Each copy is responsible for working with one of the two buffers,
and writes a single character to the other copy when the buffer is complete.
YUCCCCCCH! KLUDGE KLUDGE KLUDGE!
How about it, Bell Labs? If you are going to provide non-blocking I/O, I
really think you should give us a way to find out when the I/O is complete.
I fully realize the difficulty of integrating such a feature into the Unix
design; but I still think you should do it the right way.
More information about the Comp.unix.wizards
mailing list