termio(7) and read(2) problem!

John Buck john at polyof.UUCP
Tue Jan 10 09:58:12 AEST 1989


In article <137 at zebra.UUCP>, vern at 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 at polyof.poly.edu
john at polygraf.bitnet
trixie!polyof!john  (UUCP)
Polytechnic University
Farmingdale, NY



More information about the Comp.sys.att mailing list