From: Ian AT kiwiplan DOT co DOT nz (Ian Collins) Subject: "bug" in select call - help. 13 Mar 1998 02:24:26 -0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain To: "'Gnu Mailing list'" 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 #include #include 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 "gnu-win32-request AT cygnus DOT com" with one line of text: "help".