Subject: Strange select behaviour in b19
From: [email-masked] (Ian Collins)

10 Mar 1998 23:38:16 -0800
Message-ID: <C1A9DAABC292D111A4D90000F879A2BA0E98.cygnus.gnu-win32@NTMAIL>
Mime-Version: 1.0
Content-Type: text/plain
To: "'Gnu Mailing list'" <[email-masked]>

The easiest way to describe the wrong behaviour is to run the following
program. 
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_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");
      break;
    }
    else if (nfound == 0){
      printf("Select timed out\n");
    }
    else {
      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".