Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: <8AC36D3167EED41184C800508BD95405120E82@apollo.adtech-inc.com> From: "Ching, Jimen" To: "'cygwin AT sources DOT redhat DOT com'" Subject: select and DOS box click Date: Thu, 1 Mar 2001 15:45:55 -1000 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Hi all, I was wondering if someone could tell me if the following behavior is what is expected. I run the program below with cygwin 1.1.8. Two strange behavior seems to occur. 1. If I click on the DOS box where this program is running, the select call returns 1. The output will show this. But the call to read will block. Probably because there is no input from the keyboard. Is this the correct behavior? How do I check only for keyboard input? Note: clicking on the title bar does not cause this behavior. It only happens if you click inside the window. 2. When I run the program from the DOS prompt and hit Ctrl-Z, the program freezes. But if I run the program in bash and hit Ctrl-Z, the program is suspended. Is this normal? The problem in #1 did not occur in 1.1.6. Since setup.exe does not let me back-rev to 1.1.6, I can not verify this. Any info is greatly appreciated. --jc --------------------------------------------------------------------- #include #include #include #include #include int cbreak(void) { struct termios tio, orig; if (tcgetattr(STDIN_FILENO, &orig) < 0) { fprintf(stderr, "tcgetattr failed.\n"); return -1; } tio = orig; tio.c_lflag &= ~(ICANON); tio.c_cc[VMIN] = 0; tio.c_cc[VTIME] = 0; if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio) < 0) { fprintf(stderr, "tcsetattr failed.\n"); return -1; } return 0; } int main(int argc, char *argv[]) { fd_set rfds, efds; int fds, fd_max; /* Need key-at-a-time input for test. */ cbreak(); while (1) { FD_ZERO(&rfds); FD_ZERO(&efds); FD_SET(STDIN_FILENO, &rfds); FD_SET(STDIN_FILENO, &efds); fd_max = STDIN_FILENO; fds = select(fd_max + 1, &rfds, 0, &efds, 0); printf("Select returned with %d ready fds.\n", fds); if (fds && FD_ISSET(STDIN_FILENO, &rfds)) { char buf[80]; int len; len = read(STDIN_FILENO, buf, sizeof(buf) - 1); if (len > 0) { buf[len] = '\0'; printf("Data read: %s (%d)\n", buf, len); } else if (len < 0) perror("read"); else { printf("EOF detected on stdin, quiting...\n"); break; } --fds; } if (fds && FD_ISSET(STDIN_FILENO, &efds)) { printf("Exception detected on stdin, quiting...\n"); --fds; break; } } return 0; } --------------------------------------------------------------------- -- jching AT adtech-inc DOT com Adtech, Inc. (808) 734-3300 -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple