non-blocking read
mark at elsie.UUCP
mark at elsie.UUCP
Mon Feb 6 22:02:00 AEST 1984
If you have the Berkeley new tty driver you can do the following:
#include <sgtty.h>
foo()
{
int nchars = 0;
for (;;) {
..loop code..
ioctl(0,FIONREAD,(struct sgttyb *) &nchars);
if (nchars) {
/* Something has been typed at the keyboard */
..anything else..
}
}
}
The FIONREAD causes the number of chars waiting at the terminal to be placed
in nchars. NOTE: if you want to process single chars as they come into the
terminal you must be in RAW or CBREAK mode.
This is not terribly portable (I try to protect such code with
"#ifdef berkeley"'s). I would be interested in knowing if there is a truly
portable way of doing this.
--
Mark J. Miller
NIH/NCI/DCE/LEC
UUCP: decvax!harpo!seismo!rlgvax!cvl!elsie!mark
Phone: (301) 496-5688
More information about the Comp.unix
mailing list