slowtimer.c

来自「TCP-IP红宝书源代码」· C语言 代码 · 共 45 行

C
45
字号
/* slowtimer.c - slowtimer */

#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <sleep.h>
#include <date.h>
#include <network.h>

#define	STGRAN	1		/* Timer granularity (delay) in seconds	*/

void arptimer(unsigned), ipftimer(unsigned), rttimer(unsigned);
#ifdef OSPF
void ospftimer(unsigned);
#endif /*OSPF*/

/*------------------------------------------------------------------------
 * slowtimer - handle long-term periodic maintenance of network tables
 *------------------------------------------------------------------------
 */
PROCESS
slowtimer(void)
{
	unsigned long	lasttime, now;	/* prev and current times (secs)*/
	int		delay;		/* actual delay in seconds	*/

	signal(Net.sema);

	gettime(&lasttime);
	while (1) {
		sleep(STGRAN);
		gettime(&now);
		delay = now - lasttime;
		if (delay <= 0 || delay > 4*STGRAN)
			delay = STGRAN;	/* likely clock reset */
		lasttime = now;
		arptimer(delay);
		ipftimer(delay);
		rttimer(delay);
#ifdef OSPF
		ospftimer(delay);
#endif /* OSPF */
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?