alarms and longjmp

Rick Peralta fbp at cybvax0.UUCP
Fri Aug 9 00:29:28 AEST 1985


What is the proper behavior of an alarm call.

Below is an extract of a public domain program. 
To get it to work on a VAX (4.2) I made some changes.
What is the proper way to handle the timeout condition ?
Is the original way "legal" (I know it works on most machines) ?
Also what liabilities are incured by calling setjmp so frequently ?

Any suggestions, comments or discussion welcome.


#ifdef BSD
#include	<setjmp.h>
jmp_buf	alrmbuf ;
#endif

/* receive a byte from sender */
recvbyte(seconds,bitmask)
unsigned seconds;
int bitmask;
{
	char c;
	int alarmfunc();		/* forward declaration */
#ifdef BSD
 	if ( setjmp (alrmbuf) )
 		return (TO) ;
#endif
	signal(SIGALRM,alarmfunc);	/* catch alarms */
	alarm(seconds);			/* set clock */
	if (read (0, &c, 1) < 0)	/* get char or timeout */
		return (TO);
	alarm(0);			/* clear clock */
	return (c&bitmask);
}

/* dummy alarm function */
alarmfunc()
{
#ifdef BSD
 	longjmp ( alrmbuf, 1 );
#endif
	return;
}


Rick  ...!cybvax0[!dmc0]!fbp

"A likely story.  I don't believe a word of it."



More information about the Comp.unix mailing list