home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / linux / 22713 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.5 KB  |  48 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!sol.ctr.columbia.edu!eff!world!jrs
  3. From: jrs@world.std.com (Rick Sladkey)
  4. Subject: Re: non-blocking read(): return vaules?
  5. In-Reply-To: erc@unislc.uucp's message of Mon, 4 Jan 1993 20:25:58 GMT
  6. Message-ID: <JRS.93Jan4201620@lepton.world.std.com>
  7. Sender: jrs@world.std.com (Rick Sladkey)
  8. Organization: The Internet
  9. References: <1993Jan4.103822.13815@klaava.Helsinki.FI>
  10.             <1993Jan4.202558.16223@unislc.uucp>
  11. Date: Tue, 5 Jan 1993 01:16:20 GMT
  12. Lines: 34
  13.  
  14. >>>>> On Mon, 4 Jan 1993 20:25:58 GMT, erc@unislc.uucp (Ed Carp) said:
  15.  
  16. Ed> The problem with this is, if you have SVR3 code lying around
  17. Ed> (which is the majority of my source code), you have to check the
  18. Ed> return value from the read AND errno.  If errno == EAGAIN, retry
  19. Ed> the read (possibly sleeping or doing a select() so you don't lock
  20. Ed> the processor into a hard loop).
  21.  
  22. Ed> What is the most efficient way of doing this?  I've been bitten by
  23. Ed> this one several times.  cu also had this bug until I worked up a
  24. Ed> patch for it, too.
  25.  
  26. Include this header in files that count on such behavior.
  27.  
  28. /* sysv_read.h - emulate sysv-style non-blocking read under linux */
  29.  
  30. #ifndef _SYSV_READ_H
  31. #define _SYSV_READ_H
  32. #include <unistd.h>
  33. #include <errno.h>
  34.  
  35. static inline ssize_t sysv_read (int __fd, __ptr_t __buf, size_t __nbytes)
  36. {
  37.     ssize_t __result = __read (__fd, __buf, __nbytes);
  38.  
  39.     return __result < 0 && errno == EAGAIN ? 0 : __result;
  40. }
  41.  
  42. #define read sysv_read
  43.  
  44. #endif
  45. --
  46. Rick Sladkey
  47. jrs@world.std.com
  48.