Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-crg.llnl.gov!bowles From: bowles@lll-crg.llnl.gov (Jeff Bowles) Newsgroups: comp.unix.questions Subject: Re: how to poll keyboard Message-ID: <11069@lll-winken.llnl.gov> Date: 5 Aug 88 15:28:16 GMT References: <5065@husc6.harvard.edu> <62727@sun.uucp> Sender: usenet@lll-winken.llnl.gov Reply-To: bowles@lll-crg.llnl.gov.UUCP (Jeff Bowles) Organization: Lawrence Livermore National Laboratory Lines: 27 In article <62727@sun.uucp> swilson@sun.UUCP (Scott Wilson) writes: >In article <5065@husc6.harvard.edu> nakada@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