non-blocking read

moss%brl-vld at sri-unix.UUCP moss%brl-vld at sri-unix.UUCP
Fri Feb 10 02:47:41 AEST 1984


From:      Gary S Moss ~Software Development Team~ <moss at brl-vld>

> if the program somehow exits after the "fcntl( 0, F_SETFL, O_NDELAY )",
> you will get spontaneously logged off.

Good point Dave.
When I first implemented the code, I didn't save the file status flags,
and got logged out immediately upon exiting.  Trapping interrupts is
a good idea in any program that does some sort of clean-up, I may have
left other details out in the attempt to be concise.  Opening /dev/tty
sounds like a good idea, I'll give it a try.

One thing I neglected to mention, is that after clearing the ICANON bit
in the termio structure, you will want to mask off the sign bit :

#define CMASK	0377
int	c;	/* Good idea using int if comparing to constants.	*/
	
	if( read( 0, (char *)&c, 1 ) )
		switch( c & CMASK )
		UP: ...
- Moss.



More information about the Comp.unix mailing list