markd@iti.org (Mark Delany) (09/30/90)
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 <stdio.h> #include <sys_2.3/types.h> /* Don't ask me why this is in sys_2.3! */ #include <sys/select.h> 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 ------------ ----------------- ---------------------
ronald@robobar.co.uk (Ronald S H Khoo) (10/01/90)
In article <markd.654670818@sunchat> markd@iti.org (Mark Delany) writes: >I'm having trouble using select() and I was wondering whether: > b) There is a problem with this on Xenix at my rev This is the one! 2.3.1 Xenix doesn't select() properly on pipes. You will need the maintenance supplement UFM a.k.a xnx155b which is available for anon UUCP from sosco. -- ronald@robobar.co.uk | +44 81 991 1142 (O) | +44 71 229 7741 (H) | YELL! "Nothing sucks like a VAX" -- confirmed after recent radiator burst! Hit 'R' <RETURN> to continue .....