home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!sol.ctr.columbia.edu!eff!world!jrs
- From: jrs@world.std.com (Rick Sladkey)
- Subject: Re: non-blocking read(): return vaules?
- In-Reply-To: erc@unislc.uucp's message of Mon, 4 Jan 1993 20:25:58 GMT
- Message-ID: <JRS.93Jan4201620@lepton.world.std.com>
- Sender: jrs@world.std.com (Rick Sladkey)
- Organization: The Internet
- References: <1993Jan4.103822.13815@klaava.Helsinki.FI>
- <1993Jan4.202558.16223@unislc.uucp>
- Date: Tue, 5 Jan 1993 01:16:20 GMT
- Lines: 34
-
- >>>>> On Mon, 4 Jan 1993 20:25:58 GMT, erc@unislc.uucp (Ed Carp) said:
-
- Ed> The problem with this is, if you have SVR3 code lying around
- Ed> (which is the majority of my source code), you have to check the
- Ed> return value from the read AND errno. If errno == EAGAIN, retry
- Ed> the read (possibly sleeping or doing a select() so you don't lock
- Ed> the processor into a hard loop).
-
- Ed> What is the most efficient way of doing this? I've been bitten by
- Ed> this one several times. cu also had this bug until I worked up a
- Ed> patch for it, too.
-
- Include this header in files that count on such behavior.
-
- /* sysv_read.h - emulate sysv-style non-blocking read under linux */
-
- #ifndef _SYSV_READ_H
- #define _SYSV_READ_H
- #include <unistd.h>
- #include <errno.h>
-
- static inline ssize_t sysv_read (int __fd, __ptr_t __buf, size_t __nbytes)
- {
- ssize_t __result = __read (__fd, __buf, __nbytes);
-
- return __result < 0 && errno == EAGAIN ? 0 : __result;
- }
-
- #define read sysv_read
-
- #endif
- --
- Rick Sladkey
- jrs@world.std.com
-