longjmp + signal may cause problems

Stephen Hemminger steveh at hammer.UUCP
Wed Dec 7 09:43:54 AEST 1983


--------
The obvious way around the problem with 4.2/4.1c is to use a select
and not use a signal at all!

/* NOT TESTED */
#include	<sys/types.h>
#include	<time.h>

int
dt_ioget(dt, sec)
register DECTALK	*dt;	/* DECtalk device		*/
int			sec;	/* Wait time, 0 == forever	*/
/*
 * UNIX:  Fill the input buffer, return the next (first) character.
 */
{
	register int	incount;	/* Count and error code	*/
	int    fdmask;			/* file descriptor mask for select() */
	struct	timeval	timeout;	/* timeout value for select() */

	/*
	 * Return buffered character (if any)
	 */
	if (dt->in_ptr < dt->in_end) 
	    return (*dt->in_ptr++ & 0xFF);
	/*
	 * We must refill the buffer
	 */
	dt->in_ptr = dt->in_end = &dt->in_buff[0];
	dt_ioput(dt, 0);		/* Flush output		*/
	if (dt_abort)
	    return (DT_ERROR);
	/* Berkeley Unix 4.2 has a nice way of doing this */
	fdmask = 1<<dt->unit);
	timeout.tv_usec = 0;
	timeout.tv_sec = sec;
	if(select(1, &fdmask, 0, 0, 0, &timeout) < 0)
		return (DT_ERROR);
	if(fdmask == 0)
		return (DT_TIMEOUT)
	incount = read(dt->unit, dt->in_buff, IN_BUFLEN);

	dt->in_end = &dt->in_buff[incount];
	return (*dt->in_ptr++ & 0xFF);
}



More information about the Comp.unix.wizards mailing list