Subject: Bug in select call - fixed (worked around).
From: [email-masked] (Ian Collins)

17 Mar 1998 14:55:15 -0800
Message-ID: <C1A9DAABC292D111A4D90000F879A2BA0EA0.cygnus.gnu-win32@NTMAIL>
Mime-Version: 1.0
Content-Type: text/plain
To: "'Gnu Mailing list'" <[email-masked]>

An interesting solution to the below problem which has worked on three
PC's (NT SP3) with b19.
In the cygnus.bat script, I had,
SET CYGWIN32=title tty

By changing this to,
SET CYGWIN32=tty

The select problem went away (I'm serious).

> I believe there is a problem with the select call on b19.
> 
> The problem arises when select is used to detect input or timeouts
from channel 0.
> If select times out BEFORE a character has been input, then the next
time select is called, it 
> returns with a timeout IMMEDIATELY.
> Once a character has been input, then everything is OK (i.e., select
returns timeouts properly).
> 
> The easiest way to describe this behavior is with the following
program.
> Run this program, but DONT hit a character.
> After 5 seconds it will time out.
> After another 5 seconds, the screen scrolls with continuous timeout
messages (select returns zero).
> 
> However, if you run the program and immediately input a character
(don't forget the ENTER as the
> program doesn't set tty to raw), then the select works fine.
> 
> Does anyone have an explanation/fix for this.
> 
> This problem is a follow up to an earlier post about signal handling
in gnu 19. The signal handling
> did not work as I required it, so someone suggested (thanks Tim) that
I recode using select.
> 
> /* ============================================== */
> #include <stdio.h>
> #include <fcntl.h>
> #include <sys/time.h>
> 
> main() {
>  struct fd_set readfds;
>   struct timeval timeout;
>   int nfound;
>   int i;
>   char c[1];
> 
>   while (1) {
> 	 FD_ZERO(&readfds);
>     FD_SET(0,&readfds);
> 
>     timeout.tv_sec=5;       /* time out after 5 seconds */
>     timeout.tv_usec= 0;
> 
>     nfound = select( 1, &readfds, 0, 0, &timeout);
>     if( nfound == -1 ){
>       printf("select return -1\n");     /* An error */
>       break;
>     }
>     else if (nfound == 0){
>       printf("Select timed out\n");     /* a timeout */
>     }
>     else {                              /* there is data in the buffer
to read */
>       printf("Select thinks there is something to read\n");
>       i = read(0, c, 1);
>       printf("Read %c\n", c[0]);
>       if (c[0] == 81) break;
>     }
>   }
> }

Ian Collins. 
KIWIPLAN NZ.

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".