home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / hp / 15139 next >
Encoding:
Text File  |  1993-01-21  |  2.4 KB  |  81 lines

  1. 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
  2. From: glenm@ephor.tusc.oz.au (Glen McCallum)
  3. Newsgroups: comp.sys.hp
  4. Subject: Re: select() behavior on a pipe
  5. Message-ID: <1jl4tjINNqej@ephor.tusc.oz.au>
  6. Date: 21 Jan 93 03:22:27 GMT
  7. References: <8321@tivoli.UUCP>
  8. Organization: TUSC Computer Systems Pty Ltd.
  9. Lines: 69
  10. NNTP-Posting-Host: ephor.tusc.oz.au
  11.  
  12. In <8321@tivoli.UUCP> stuart@TIVOLI.COM (Stuart Jarriel) writes:
  13.  
  14. >I am trying to work with a chunk of code that does a select() on a named
  15. >pipe to watch for possible commands.  
  16.  
  17. >This works just fine as long as there is a writer on the pipe at all times.
  18. >But if the writer exec's, writes and exits, the select will always return
  19. >with data indicated on the pipe, even though there is none available.
  20.  
  21. >This behavior is different than other systems, and I wonder if it isnt
  22. >something in the my code rather than an HPUX problem.  Has anyone ever
  23. >worked with this?
  24.  
  25. >stuart
  26.  
  27. Yes.  I have seen this bug.  On HP-UX when using select(2) on pipes, if an
  28. exceptional condition occurs, the 'read' fd_mask is erroneously set instead
  29. of the 'exception' fd_mask.
  30. A workaround is to fstat(2) the pipe to verify whether or not data is actually
  31. there ..
  32.  
  33. >(sample code...)
  34.  
  35. .. earlier stuff deleted ..
  36.  
  37. struct stat    statb;
  38.  
  39. >    tv.tv_sec = 5;
  40. >    tv.tv_usec = 0;
  41. >    readmask = 1 << fd;
  42. >    fd_mask = readmask;
  43.  
  44. >    printf("into select\n");
  45. >    while(1) {
  46. >        if (select(fd+3, &readmask, 0, 0, &tv)) {
  47. >            if (readmask & fd_mask) {
  48.                 if (fstat(fd, &statb) < 0) {
  49.                 fprintf(stderr, "fstat(2) bombed\n");
  50.                 } else if (statb.st_size > 0) {
  51. >                size = TST_SIZE;
  52. >                cntr++;
  53. >                if ((retval = read_packet(buf, size)) < 0) {
  54. >                    printf("%d read_packet = %d, errno =  %d\n", 
  55. >                            cntr, retval, errno);
  56. >                } else {
  57. >                    printf(".");
  58. >                }
  59.                 } else {
  60.                 fprintf(stderr, "pipe has been broken\n");
  61.                 /* .. and other error-type stuff .. */
  62.                 }
  63. >            }
  64. >        } else {
  65. >            printf("-");
  66. >            fflush(stdout);
  67. >        }
  68. >    }
  69. >}
  70.  
  71. Note that fstat(2) is not guaranteed to work with pipes according to POSIX.1,
  72. but I have used this kind of technique successfully with HP-UX 8.0 and
  73. SCO-ODT 1.0/1.1.
  74.  
  75. --
  76. ------------------------ Glen McCallum (glenm@tusc.oz.au) ----------------------
  77.  
  78. #include <standard_disclaimer>
  79.  
  80. - TUSC Computer Systems, 666 Doncaster Rd, Doncaster, Victoria 3108, Australia -
  81.