home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!sgiblab!munnari.oz.au!bruce.cs.monash.edu.au!merlin!ephor.tusc.oz.au!ephor.tusc.oz.au!not-for-mail
- From: glenm@ephor.tusc.oz.au (Glen McCallum)
- Newsgroups: comp.sys.hp
- Subject: Re: select() behavior on a pipe
- Message-ID: <1jl4tjINNqej@ephor.tusc.oz.au>
- Date: 21 Jan 93 03:22:27 GMT
- References: <8321@tivoli.UUCP>
- Organization: TUSC Computer Systems Pty Ltd.
- Lines: 69
- NNTP-Posting-Host: ephor.tusc.oz.au
-
- In <8321@tivoli.UUCP> stuart@TIVOLI.COM (Stuart Jarriel) writes:
-
- >I am trying to work with a chunk of code that does a select() on a named
- >pipe to watch for possible commands.
-
- >This works just fine as long as there is a writer on the pipe at all times.
- >But if the writer exec's, writes and exits, the select will always return
- >with data indicated on the pipe, even though there is none available.
-
- >This behavior is different than other systems, and I wonder if it isnt
- >something in the my code rather than an HPUX problem. Has anyone ever
- >worked with this?
-
- >stuart
-
- Yes. I have seen this bug. On HP-UX when using select(2) on pipes, if an
- exceptional condition occurs, the 'read' fd_mask is erroneously set instead
- of the 'exception' fd_mask.
- A workaround is to fstat(2) the pipe to verify whether or not data is actually
- there ..
-
- >(sample code...)
-
- .. earlier stuff deleted ..
-
- struct stat statb;
-
- > tv.tv_sec = 5;
- > tv.tv_usec = 0;
- > readmask = 1 << fd;
- > fd_mask = readmask;
-
- > printf("into select\n");
- > while(1) {
- > if (select(fd+3, &readmask, 0, 0, &tv)) {
- > if (readmask & fd_mask) {
- if (fstat(fd, &statb) < 0) {
- fprintf(stderr, "fstat(2) bombed\n");
- } else if (statb.st_size > 0) {
- > size = TST_SIZE;
- > cntr++;
- > if ((retval = read_packet(buf, size)) < 0) {
- > printf("%d read_packet = %d, errno = %d\n",
- > cntr, retval, errno);
- > } else {
- > printf(".");
- > }
- } else {
- fprintf(stderr, "pipe has been broken\n");
- /* .. and other error-type stuff .. */
- }
- > }
- > } else {
- > printf("-");
- > fflush(stdout);
- > }
- > }
- >}
-
- Note that fstat(2) is not guaranteed to work with pipes according to POSIX.1,
- but I have used this kind of technique successfully with HP-UX 8.0 and
- SCO-ODT 1.0/1.1.
-
- --
- ------------------------ Glen McCallum (glenm@tusc.oz.au) ----------------------
-
- #include <standard_disclaimer>
-
- - TUSC Computer Systems, 666 Doncaster Rd, Doncaster, Victoria 3108, Australia -
-