But I don't wanna do non-blocking I/O...
John Chambers
jc at minya.UUCP
Tue Jun 12 12:27:19 AEST 1990
Well, here's a little puzzle that has me stumped; maybe
someone out there can tell me what an idiot I've been for
overlooking ______________ (fill in the blank).
What I've got is an application that I'm trying to port
from BSD to SYS/V (ESIX, actually, 5.3 on a 386). The
application does stuff (which you don't want to know
about ;-) via a serial port, and it normally runs with
the port in raw mode (-icanon, of course). Sometimes,
it needs to put the port back into a cooked state and
start up a shell to talk to whatever is on the other
side of the port. The shell starts up, but the port
is still in some sort of half-baked mode that does
non-blocking I/O. When the shell reads, it gets eof
immediately and exits. Durned if I can puzzle out why.
I've added code to dump the status of the struct termio
just before the exec is done, and it says:
File 0: cflag=004275
File 0: iflag=006446
File 0: lflag=000073
File 0: oflag=014005
I've also had it invoke a shell of my own for which I
have the source so I can make it do an ioctl and show
the result, and it gives exactly the same numbers as
above. According to the termio(7) manual 'page', the
above lflag bits include the 02 bit, which is ICANON,
so the driver should be assembling input into lines,
and not returning anything until it gets an eol char.
But fgets(buf,n,stdin) returns EOF immediately. My
(mis?)reading of the termio man page says that the
above flags couldn't possibly do non-blocking I/O,
but that's what happens.
I've also had my shell do a 10-sec wait before exiting,
so I can go to another window and run stty on the port;
the stty agrees with all the bits in the above flags,
in particular it says that icanon is on.
It appears there is some way of doing non-blocking I/O
on Sys/V which is unknown to me (and which I can't find
in TFM), but which is known to this program. I've tried
grepping for all the likely suspects. There are no calls
of fcntl. The only calls of ioctl are the ones that set
raw mode initially and the above cooked mode just before
calling a shell. The open() does include F_NDELAY, but
this is supposed to apply only to the open; it shouldn't
set non-blocking I/O permanently for the file (I hope ;-).
The string "NBIO" does not occur in the code, in upper
or lower case.
An especially curious aspect is that this code starts
shells successfully on BSD and Ultrix systems, and also
on a SYS/V.2 system that I tried it on. The non-blocking
I/O doesn't happen there, only on 5.3.
Does anyone know how else one might enable non-blocking
I/O on a Sys/V.3 serial port? Where might I look in the
manual that I haven't mentioned above? And how should I
suppress non-blocking I/O?
[Non-blocking I/O certainly isn't one of the more-portable
or better-documented parts of Unix. ;-]
--
Uucp: ...!{harvard.edu,ima.com,mit-eddie.edu}!minya!jc (John Chambers)
Home: 1-617-484-6393
Work: 1-508-952-3274
Cute-Saying: It's never to late to have a happy childhood.
More information about the Comp.unix.wizards
mailing list