⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrutil.c

📁 用于嵌入式系统的TCP/IP协议栈及若干服务
💻 C
字号:
/**            Copyright (c) 1998-2001 by NETsilicon Inc.**  This software is copyrighted by and is the sole property of*  NETsilicon.  All rights, title, ownership, or other interests*  in the software remain the property of NETsilicon.  This*  software may only be used in accordance with the corresponding*  license agreement.  Any unauthorized use, duplication, transmission,*  distribution, or disclosure of this software is expressly forbidden.**  This Copyright notice may not be removed or modified without prior*  written consent of NETsilicon.**  NETsilicon, reserves the right to modify this software*  without notice.**  NETsilicon*  411 Waverley Oaks Road                  USA 781.647.1234*  Suite 227                               http://www.netsilicon.com*  Waltham, MA 02452                       AmericaSales@netsilicon.com***************************************************************************  $Name: Fusion 6.52 Fusion 6.51 $*  $Date: 2001/09/20 10:27:12 $*  $Source: M:/psisrc/routing/rip/rcs/rrutil.c $*  $Revision: 1.6 $****************************************************************************  File Description: Generic router utility functions ***************************************************************************/#include "riproute.h"#include "rrport.h"#include "rrtypes.h"#include "rribd.h"#include "rrproto.h"fnc_prot(static void, rrTimerLink,(rrtimer_pt,rrthead_pt))fnc_prot(static void, rrTimerUnlink,(rrtimer_pt,rrthead_pt))/**********************************************rrTimerLink:link a timer entry in the appropriate placeon the timer list, based on time.**********************************************/static void rrTimerLink(rrtimer_pt t,rrthead_pt head){	rrtimer_pt t2;	int odelta,cum;	/* if list empty, start the list */	if(head->dll_fwd == NULL){		t->t_fwd = NULL;		t->t_bwd = NULL;		head->dll_fwd = t;		head->dll_bwd = t;		t->t_delta = t->t_time;	}	else{		/* find where to put this in the order */		for( t2 = head->dll_fwd, cum = 0;		  	t2; t2 = t2->t_fwd){		  	cum += t2->t_delta;			if(cum > t->t_time){				break;			}		}		/* link in front of t2 (if there is one) */		if(t2){			t->t_fwd = t2;			t->t_bwd = t2->t_bwd;			t2->t_bwd = t;			if(t->t_bwd){				t->t_bwd->t_fwd = t;			}			else{				head->dll_fwd = t;			}			odelta = t2->t_delta;			t2->t_delta = cum - t->t_time;			t->t_delta = odelta - t2->t_delta;		}		else{			/* goes at end of list */			t2 = head->dll_bwd; /* old end */			head->dll_bwd = t;			t2->t_fwd = t;			t->t_fwd = 0;			t->t_bwd = t2;			t->t_delta = t->t_time - cum;		}	}}/*******************************************************rrTimerUnlink:remove timer entry from list.*******************************************************/static void rrTimerUnlink(rrtimer_pt t,rrthead_pt head){	rrtimer_pt t2;	/* verify it really is on list */	for( t2 = head->dll_fwd; t2; t2 = t2->t_fwd)		if(t2 == t) break;	/* if not on active list, return */	if(!t2) return;	/* first adjust delta time of following	   entry.	*/	if(t->t_fwd)		t->t_fwd->t_delta += t->t_delta;	/* now unlink */	if(t->t_bwd)		t->t_bwd->t_fwd = t->t_fwd;	else		head->dll_fwd = t->t_fwd;	if(t->t_fwd)		t->t_fwd->t_bwd = t->t_bwd;	else		head->dll_bwd = t->t_bwd;}		        /*********************************************************rrTimerCreate:  entry is added to timer linked list.  elements in this list are ordered in ascending  time to live (ttl). times kept in the structure   are delta from previous so that we only need check  the first element on a "tic".callback: function to call on expirationparam:    parameter passed to callbacktime:     timer timetype:	one of: TTYPE_ONESHOT, TTYPE_CYCLIC**********************************************************/rrtimer_pt rrTimerCreate(vfcnptr callback,			  void *param,int time,int type,rrthead_pt head){	rrtimer_pt t;	/* try to alloc struct */	if( (t = (rrtimer_pt)rrTimerAlloc(sizeof(rrTIMER))) == 0 )		return(0);	t->t_callback = callback;	t->t_param = param;	t->t_type = type;	t->t_time= time;	/* now link it */	rrTimerLink(t,head);			return(t);}/*****************************************************rrTimerDelete:delete a timer entry.*****************************************************/void rrTimerDelete(rrtimer_pt t,rrthead_pt head){	if(!t) return;	/* unlink it */	rrTimerUnlink(t,head);	/* dealloc */	rrTimerFree(t);}/**************************************************rrTimerSet:modify the time before timer expiration.**************************************************/void rrTimerSet(rrtimer_pt t,int newtime,vfcnptr newfcn,rrthead_pt head){	if(!t) return;	/* remove from list */	rrTimerUnlink(t,head);	/* new params */	t->t_time = newtime;	t->t_callback = newfcn;	/* add back */	rrTimerLink(t,head);}/***********************************************rrTimerDisable:deactivates a timer by taking it out of thelist, but not freeing it. Note its OK to callthis if were not in the list already.***********************************************/void rrTimerDisable(rrtimer_pt t,rrthead_pt head){	if(!t) return;	rrTimerUnlink(t,head);}/***********************************************rrTimerEnable:***********************************************/void rrTimerEnable(rrtimer_pt t,rrthead_pt head){	if(!t) return;	rrTimerLink(t,head);}/***********************************************rrProcTimers:   checks timer list by decrementing   first element. When this goes to zero:   - the related function is called.   - the next element is moved to the head of	the list.Note that more than one entry can expire at atime.***********************************************/void rrProcTimers(rrthead_pt head){	rrtimer_pt t;	void *(* cb)(void *);	/* decrement head */	if( (t = head->dll_fwd) != 0 )		--t->t_delta;	while( (t = head->dll_fwd) != 0 && t->t_delta <=  0 )	{		rrTimerUnlink(t,head);		/* restart if cyclic */		if(t->t_type == TTYPE_CYCLIC)			rrTimerLink(t,head);		/* do callback */		/* callback may call timerdelete */		cb = t->t_callback;		(*cb)(t->t_param);	}}/*********************************************rrCopyMemUp:backwards copy so can copy from low to highwithout overwriting**********************************************/void rrCopyMemUp(byte *dst,byte *src,int len){	byte *sp,*dp;		dp = dst+len;	sp = src+len;	while(len){		*(--dp) = *(--sp);		len--;	}}

⌨️ 快捷键说明

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