[ale] Mixing Alarm and Sleep

Chris Fowler cfowler at outpostsentinel.com
Mon Jan 21 14:53:22 EST 2002



Ah!  I'm having some issues using the alarm() call and the sleep() call in the same program.  The alarm call is in a library function.  Basically, another piece of source code.  It uses the alarm to timeout on sending
and receiveing data over udp.   I nede to loop and sleep for 30 seconds.    The sleep is not sleeping for 30 seconds.   Bacically it would look like this.



send.c - part of a library
--------------------------

catchAlarm(int signum)
{
	ALARM=1
}

int
send{char *ip)
{
	signal(SIGALRM, catchAlarm)
	alarm(60);
	
	/* send */

	/* receive */

	alarm(0);

	return CODE;
}


--------------------------------
daemon.c


int
main(int argc, char *argv[])
{

	int code;

	for(;;)
	{
		code = send("127.0.0.1");
		
		/* Do something */

		sleep(30);
	}

	reutrn 0;
}


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list