home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / ultrix / 9003 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.7 KB

  1. Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!uka!news!hf
  2. From: hf@tk.telematik.informatik.uni-karlsruhe.de (Harald Fuchs)
  3. Newsgroups: comp.unix.ultrix
  4. Subject: Inconsistent behavior of ioctl(FIONREAD)
  5. Date: 21 Dec 92 12:03:51
  6. Organization: Karlsruhe University, Germany
  7. Lines: 28
  8. Message-ID: <HF.92Dec21120351@whyaduck.tk.telematik.informatik.uni-karlsruhe.de>
  9. NNTP-Posting-Host: whyaduck.telematik.informatik.uni-karlsruhe.de
  10.  
  11. While integrating slow data sources like ttys or sockets into a
  12. homemade lightweight process package I noticed a strange behavior
  13. of ioctl(FIONREAD).
  14.  
  15. Basically, I do the following:
  16. 1) Set the file descriptor to nonblocking and asynchronous with
  17.    ioctl(FIONBIO) resp. ioctl(FIOASYNC)
  18. 2) When Ultrix hits me with a SIGIO, I do a select() with timeout=0
  19. 3) For all descriptors in the returned rmask, I want to know if there
  20.    has anything happened *without trying to read* from them. So I do
  21.    ioctl(FIONREAD).
  22.  
  23. This works fine so far, but there is a problem with EOF. When I get
  24. EOF on a tty, Ultrix sends me a SIGIO (as it should), select() sets
  25. the corresponding descriptor in the rmask (as it should), and
  26. ioctl(FIONREAD) returns 1. With sockets, everything is the same except
  27. that ioctl(FIONREAD) returns 0.
  28. Returning 0 sounds reasonable since there are no more bytes to read.
  29. Returning 1 sounds reasonable, too, since the fd has got the
  30. information that it has reached eof, thus causing the next read() to
  31. return without EWOULDBLOCK.
  32. But I think the inconsistent behavior described above could be called
  33. a bug. Unfortunately, I couldn't find anything in the documentation
  34. about the return value of ioctl(FIONREAD) in case of eof. What do you
  35. think?
  36. --
  37.  
  38. Harald Fuchs <hf@tk.telematik.informatik.uni-karlsruhe.de>
  39.