Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!sun-barr!newstop!sunaus.oz!markd From: markd@iti.org (Mark Delany) Newsgroups: comp.unix.xenix.sco Subject: Problem with select() call Summary: Getting select() to work with pipes Keywords: SELECT Message-ID: Date: 30 Sep 90 05:00:18 GMT Sender: news@sunaus.oz Distribution: comp Organization: Sun Microsystems - Australia Lines: 91 Sorry if this is an oft repeated query, but... I'm having trouble using select() and I was wondering whether: a) I'm doing something wrong b) There is a problem with this on Xenix at my rev c) There is a known fix The system is Xenix SysV version 2.3.1 The Development system is 2.2 (I think). All I'm trying to do is select on two file units, stdin and a pipe created with pipe(). What happens is select() is always indicating "readability" on the pipe even when there is nothing to be read. As a simple demonstration, the attached prog does a select on stdin only. It works fine if stdin is the terminal, but as soon as I pipe to it, select() always returns the bit set saying there is something to read. In other words, "./prog" works, but: "cat | ./prog" doesn't! In desperation I used poll() as a work-around and it returns POLLNVAL on the pipe - sigh! Can anyone offer enlightenment? ------------------------------------------------------------- /* * Trivial prog to test select on stdin. */ #include #include /* Don't ask me why this is in sys_2.3! */ #include main() { fd_set fdset; struct timeval timeout; char buf[100]; int result; int bytes; while (1) { timeout.tv_sec = 3; timeout.tv_usec = 0; FD_ZERO(&fdset); FD_SET(fileno(stdin), &fdset); result = select(fileno(stdin) + 1, &fdset, NULL, NULL, &timeout); printf("SELECT Result gave %d with %x\n", result, FD_ISSET(fileno(stdin), &fdset)); if (result < 0) { perror("Select failed"); sleep(2); /* Slow the spin if error return */ continue; } if ((result >= 1) && FD_ISSET(fileno(stdin), &fdset)) { printf("Reading a single byte from STDIN\n"); bytes = read(fileno(stdin), buf, 1); if (bytes == 0) { printf("Eof\n"); break; } printf("SIN Read gave %d\n", bytes); } } } -- ------------ ----------------- --------------------- Mark Delany markd@Aus.Sun.COM ...!sun!sunchat!markd ------------ ----------------- ---------------------