Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!rochester!pt!ius1.cs.cmu.edu!edw
From: edw@ius1.cs.cmu.edu (Eddie Wyatt)
Newsgroups: comp.unix.questions
Subject: Re: Keyboard Input (Revised Question) ...
Message-ID: <1021@ius1.cs.cmu.edu>
Date: Sun, 26-Jul-87 21:12:51 EDT
Article-I.D.: ius1.1021
Posted: Sun Jul 26 21:12:51 1987
Date-Received: Mon, 27-Jul-87 03:44:05 EDT
References: <1043@bucsb.bu.edu.UUCP> <8569@ut-sally.UUCP>
Organization: Carnegie-Mellon University, CS/RI
Lines: 90
Keywords: Keyboard

In article <8569@ut-sally.UUCP>, hitchens@godzilla.cs.utexas.edu (Ron Hitchens, Sun Wiz) writes:
> 
>    This article is almost two weeks old, I resisted answering until I got
> caught up on comp.unix.questions.  A couple of people answered it with 
> solutions using non-blocking reads and ioctl()s, but this is a job for
> select().  If select() is available, and it is on Eric's BSD systems listed
> above, it's much better than using ioctl()s.

   If your talking about my posting of "ready_to_read" for determining
if a characters are ready to read, there is a reason why it doesn't used
"select". Plain in simple, select is a dog of a system call.  When I measure
the time it takes to call both select and ioctl on a fd associated with a
socket, I found ioctl FNREAD to be about 3 times as fast. 

  To the orignal poster,  you want to run both read_to_read or select with
CBREAKs on.

   BTW select is only better than ioctl for determining if a SINGLE port
has characters on it to read from, in that you can specify a time out value if
needed.  May I also sugguest you read the man page entry for "select".  The
synopsis specificly says the call is intended  for multiplexing.  Polling a
single line doesn't constitute multiplexing, through the system call  "select"
can obviously be used for such operations.

> 
> loop ()
> {
> 	static	struct	timeval	timer = {REFRESH_DEFAULT, 0};
> 	char	c;
> 	int inmask, nfds;
> 
> 	timer.tv_sec = refresh_time;		/* settable on cmd line */
> 	while (1) {
> 		show_stat ();			/* do it */
> 		inmask = 1;			/* gotta set the mask always */
		^^^^^^^^^^^^^^^^^^^^

		A mood point here.  If you are using BSD 4.2 this should be:

		inmask = (1<<(fileno(stdout)));

		In BSD 4.3 this should be :

		{
		fd_set inmask;
		.....

		FD_SET(fileno(stdout),&inmask);
		.........
		}
		
> 		if ((nfds = select (32, &inmask, 0, 0, &timer)) < 0) {
> 			printf ("Error doing select, I'm gettin' outta here\n");
> 			return;
> 		}
> 		if (nfds == 0)
> 			continue;		/* timer expired */
> 		read (0, &c, 1);		/* the sucker hit a key */
		     ^^^^^^^^^^
			Another mood point.  this should be -

		read(fileno(stdout),&c,sizeof(char));

			And if you are overly cautious

		if ((readval = read(fileno(stdout),&c,sizeof(char))) == -1)
			perror("read failed");
		else if (readval == 0)
			fprintf(stderr,"EOF encounter\n");

> 		switch (c) {
> 		case 'r':
> 		case 'R':
> 		case 0x12:   /* ^R */
> 		case 'l':
> 		case 'L':
> 		case 0x0C:   /* ^L */
> 			(void) wclear (stdscr);	 /* clear the physical screen */
> 			(void) wrefresh (stdscr);/* for reassuring feedback */
> 			break;
> 		default:
> 			return;
> 		}
> 	}
> }
-- 

					Eddie Wyatt

e-mail: edw@ius1.cs.cmu.edu