Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1a 12/4/83; site rlgvax.UUCP Path: utzoo!linus!decvax!harpo!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.unix Subject: Re: non-blocking read Message-ID: <1666@rlgvax.UUCP> Date: Mon, 6-Feb-84 11:32:17 EST Article-I.D.: rlgvax.1666 Posted: Mon Feb 6 11:32:17 1984 Date-Received: Thu, 9-Feb-84 03:24:06 EST References: <964@proper.UUCP> <805@elsie.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 39 The closes thing to a portable non-blocking read is: #includefrobozz(...) { register int i; i = fcntl(fdes, F_GETFL, 0); fcntl(fdes, F_SETFL, i | O_NDELAY); i = read(fdes, buf, count); #ifdef BSD4_2 if (i < 0 && errno == EWOULDBLOCK) { #else if (i == 0) { #endif /* * No characters currently available to be read. */ } else { /* * "i" contains the number of characters available to * be read. */ } This will work on System III (*if* you fix a bug in the terminal driver), System V, and 4.2BSD. *Warning*: the implementation of "fcntl" is 4.2BSD has a botch, in that the F_SETFL call is *supposed* to set the no-delay flag on the *file descriptor*, and is *only* supposed to affect *that* file descriptor (and, on S3/S5/other USG UNIX versions, it does do this); however, on 4.2BSD, it passes the no-delay flag to the driver which sets no-delay mode on the terminal port that the file descriptor refers to, so that *all* file descriptors referring to that terminal port are, in effect, set to no-delay mode. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy