Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site cybvax0.UUCP
Path: utzoo!linus!philabs!cmcl2!seismo!harvard!think!mit-eddie!cybvax0!fbp
From: fbp@cybvax0.UUCP (Rick Peralta)
Newsgroups: net.unix
Subject: alarms and longjmp
Message-ID: <666@cybvax0.UUCP>
Date: Thu, 8-Aug-85 10:29:28 EDT
Article-I.D.: cybvax0.666
Posted: Thu Aug  8 10:29:28 1985
Date-Received: Sun, 11-Aug-85 06:38:36 EDT
Distribution: net
Organization: Cybermation, Inc., Cambridge, MA
Lines: 48

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	
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."