[comp.unix.programmer] select function

djpadz@bonnie.ics.uci.edu (David Jay Padzensky) (03/21/91)

I'm writing a program that needs to use the select function to poll
for TTY input.  All I need for it to do is, given a timeout value (in
milliseconds), return a boolean value as to whether or not a key was
pressed in that time.  However, I'm having no luck with the thing.
Could somebody help me out?

Thanks in advance!

--
Dj Padzensky
_______________________________________________________________________________
Internet: djpadz@bonnie.ics.uci.edu | Neurotics build castles in the sky.
America Online: DjPadz              | Psychotics live in them.  I sell them.

jik@athena.mit.edu (Jonathan I. Kamens) (03/21/91)

In article <27E85B3B.14962@ics.uci.edu>, djpadz@bonnie.ics.uci.edu (David Jay Padzensky) writes:
|> I'm writing a program that needs to use the select function to poll
|> for TTY input.  All I need for it to do is, given a timeout value (in
|> milliseconds), return a boolean value as to whether or not a key was
|> pressed in that time.  However, I'm having no luck with the thing.
|> Could somebody help me out?

  You have not given us enough information to help you.  If you have select()
on your system, then it *is* possible to use it as you have described; this is
discussed in question 7 on the Frequently Asked Questions posting in
comp.unix.questions, with additional relevant information in question 5.

  If what you're trying to do isn't working, then you have to tell us
*exactly* what you're trying to do in order for us to be able to help you
figure out *why* it isn't working.  Therefore, I suggest you post a short
sample of code that exhibits the problem you are having, and we'll try to help.

  It's possible that the reason things aren't working for you is that you
aren't enabling cbreak mode on the terminal, which means that the input from
the user is line-buffered (so that the user can backspace and such).  Like I
said, this is discussed in the FAQ posting.  If it has expired from
comp.unix.questions at your site, you can get it:

1. Via anonymous ftp from pit-manager.mit.edu (18.72.1.58), in the
   file

   /pub/usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting]

2. Via mail archive server.  Send mail to mail-server@pit-manager.mit.edu
   with a subject of

   send usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting]

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

mouse@thunder.mcrcim.mcgill.edu (der Mouse) (03/26/91)

In article <27E85B3B.14962@ics.uci.edu>, djpadz@bonnie.ics.uci.edu (David Jay Padzensky) writes:
> I'm writing a program that needs to use the select function to poll
> for TTY input.  All I need for it to do is, given a timeout value (in
> milliseconds), return a boolean value as to whether or not a key was
> pressed in that time.  However, I'm having no luck with the thing.
> Could somebody help me out?

Not without more information, really.

One possible problem that comes to mind is that you may have neglected
to put the tty line in question into cbreak or raw mode (I assume a BSD
tty driver because you're using select()).

Note also that you generally won't get very good temporal resolution.
Most machines with UNIXish systems have clocks that tick at about 50 Hz
(sometimes 60, sometimes 100, but rarely much better than that); your
timeout will necessarily expire on a clock tick.  (You also won't
necessarily get control back immediately after the timeout expires;
other processes may run first.)

If you have a small sample program, I'd be glad to have a look at it.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu