Path: utzoo!attcan!uunet!yale!cmcl2!polyof!john From: john@polyof.UUCP ( John Buck ) Newsgroups: comp.sys.att Subject: Re: termio(7) and read(2) problem! Summary: Non-blocking reads do work Message-ID: <427@polyof.UUCP> Date: 9 Jan 89 23:58:12 GMT References: <137@zebra.UUCP> Distribution: na Organization: Polytechnic University, Farmingdale NY Lines: 42 In article <137@zebra.UUCP>, vern@zebra.UUCP (Vernon C. Hoxie) writes: > It is connected to /dev/tty000. The program opens this file with: > fd = open("/dev/tty000", O_RDWR | O_NDELAY); > Then after some other housekeeping: > char buf[512]; > . > . > k = read(fd, buf, 211); > Vernon C. Hoxie {ncar,nbires,boulder,isis}!scicom!zebra!vern Yeah, this is a common problem. the open(...O_NDELAY) is the culprit, for lack of a better word. After the open(), do a if(fcntl(fd, F_SETFL, 0) == -1){ perror("F_SETFL"); .... } The O_NDELAY, while causing the open() to return without waiting for CARRIER, also causes read()'s to return without waiting for data. Had you bothered to read the manual: READ(2)... When attempting to read a file associated with a tty that has no data currently available: If O_NDELAY is set, the read will return -1 (or 0 on some systems... JB) If O_NDELAY is clear, the read will block until data becomes available. The latter is the normal case. FCNTL(2) explains how to turn certain file flags on and off... Hope this helps. John Buck john@polyof.poly.edu john@polygraf.bitnet trixie!polyof!john (UUCP) Polytechnic University Farmingdale, NY