Subject: Re: Blocked I/O on serial ports
To: Ruschmeyer, John <jruschme@att.com>
From: Ken Hornstein <kenh@cmf.nrl.navy.mil>
List: tech-kern
Date: 08/07/1998 14:30:30
>Now, however, I hit the next problem- open() won't complete unless I use the
>O_NONBLOCK option. I assume that this is because the CM11A is not asserting
>the modem control lines.
>
>Specifcally, the CM11A has a 4-wire serial interface: TD, RD, SG, and RI
>(ring indicator).
>
>Heyu does not seem to have been written for non-blocked I/O, however. The
>major routines which read the serial port all use unchecked read(2) calls
>which usually return EAGAIN. I have put in result tests and loops (a good
>idea anyway), but it makes the background daemon process very processor
>intensive, looping on tight read loops.
Others have suggested setting local in /etc/ttys; this works, but I think
if you wanted to be _truely_ portable, you should open with O_NONBLOCK
and use fcntl() to turn off the NONBLOCK flag on that file descriptor.
Something like:
flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
--Ken