how to poll keyboard

Jeff Bowles bowles at lll-crg.llnl.gov
Sat Aug 6 01:28:16 AEST 1988


In article <62727 at sun.uucp> swilson at sun.UUCP (Scott Wilson) writes:
>In article <5065 at husc6.harvard.edu> nakada at husc8.UUCP (Paul Nakada) writes:
>>I am in need of a way to read a terminal keyboard without
>>stopping if there is no keypress...
>
>If your UNIX is sys5 based and has streams you can probably do
>the same thing with poll(2) but I have never used it.

Wrong, camel-breath! (Sorry, I'm in a giddy mood.)

The poll(2) system call that was added in System V Release 3 is an
exercise in incomplete implementations. poll(2) takes a list of
file descriptions pointing to STREAMS devices and returns when any
"interesting" event happens or when a timeout period you specify
expires. If the timeout period is 0, poll(2) returns immediately.
Examples of "interesting" events are input coming in, errors occurring
on the stream, and so on.

Unfortunately, it only works for STREAMS devices, and the tty subsystem
is the old, tried-and-not-trusted clist implementation. You can't get
there from here using poll(2) yet.

Now, if you use termio(7)  (ioctl calls) you can request read system
calls to time out, with 0.1 second granularity. Unfortunately, there's
not provisions for immediate return --- and 100 milliseconds, for some
people, feels like a long time.

	Jeff Bowles



More information about the Comp.unix.questions mailing list