📄 tcptimer.c
字号:
/***********************************************************************//* *//* Module: tcp_ip/tcptimer.c *//* Release: 2001.3 *//* Version: 99.0 *//* Purpose: TCP/IP Timer Routines *//* *//*---------------------------------------------------------------------*//* *//* Copyright 1999, Blunk Microsystems *//* ALL RIGHTS RESERVED *//* *//* Licensees have the non-exclusive right to use, modify, or extract *//* this computer program for software development at a single site. *//* This program may be resold or disseminated in executable format *//* only. The source code may not be redistributed or resold. *//* *//***********************************************************************/#include "tcp_ipp.h"/***********************************************************************//* Global Variable Definitions *//***********************************************************************/ui32 NetTickCount;static CircLink TimeoutList;/***********************************************************************//* Global Function Definitions *//***********************************************************************//***********************************************************************//* NetTimerInit: Initialize TCP/IP timer processing *//* *//***********************************************************************/void NetTimerInit(void){ TimeoutList.next_fwd = TimeoutList.next_bck = &TimeoutList;}/***********************************************************************//* NetTimerStart: Start or restart TCP/IP timer *//* *//* Inputs: timer = pointer to timer control block *//* timeout = number of ticks before expiration *//* *//***********************************************************************/void NetTimerStart(TcpTmr *timer, uint timeout){ CircLink *link; /*-------------------------------------------------------------------*/ /* Ensure timer has expiration routine. */ /*-------------------------------------------------------------------*/ TcpAssert(timer->action); /*-------------------------------------------------------------------*/ /* If we are restarting, stop timer first. */ /*-------------------------------------------------------------------*/ if (timer->running) NetTimerStop(timer); /*-------------------------------------------------------------------*/ /* Assign timer's expiration tick count. */ /*-------------------------------------------------------------------*/ timer->time_due = NetTickCount + timeout; /*-------------------------------------------------------------------*/ /* Search timeout list for timer with later expiration date. */ /*-------------------------------------------------------------------*/ for (link = TimeoutList.next_bck;; link = link->next_bck) { /*-----------------------------------------------------------------*/ /* If end of sorted list is reached, append to end. */ /*-----------------------------------------------------------------*/ if (link == &TimeoutList) { /*---------------------------------------------------------------*/ /* Append timer to end of sorted list and break. */ /*---------------------------------------------------------------*/ timer->link.next_fwd = TimeoutList.next_fwd; timer->link.next_bck = &TimeoutList; TimeoutList.next_fwd->next_bck = &timer->link; TimeoutList.next_fwd = &timer->link; break; } /*-----------------------------------------------------------------*/ /* If later expiration found, insert into sorted list and break. */ /*-----------------------------------------------------------------*/ else if (SEQ_LT(timer->time_due, ((TcpTmr *)link)->time_due)) { timer->link.next_fwd = link->next_fwd; timer->link.next_bck = link; link->next_fwd->next_bck = &timer->link; link->next_fwd = &timer->link; break; } } /*-------------------------------------------------------------------*/ /* Flag that timer is running. */ /*-------------------------------------------------------------------*/ timer->running = TRUE;}/***********************************************************************//* NetTimerStop: Stop selected timer *//* *//* Input: timer = pointer to timer control block to process *//* *//***********************************************************************/void NetTimerStop(TcpTmr *timer){ /*-------------------------------------------------------------------*/ /* If running, remove from active timers list and mark as stopped. */ /*-------------------------------------------------------------------*/ if (timer->running) { timer->link.next_bck->next_fwd = timer->link.next_fwd; timer->link.next_fwd->next_bck = timer->link.next_bck; timer->running = FALSE; }}/***********************************************************************//* NetTimerTick: Process TCP/IP timer tick *//* *//***********************************************************************/void NetTimerTick(void){ /*-------------------------------------------------------------------*/ /* Increment TCP initial segment sequence number. */ /*-------------------------------------------------------------------*/ Net.ISN += 125000; /*-------------------------------------------------------------------*/ /* Whip through timeout list, processing expired timers. */ /*-------------------------------------------------------------------*/ while (TimeoutList.next_bck != &TimeoutList) { TcpTmr *timer = (TcpTmr *)TimeoutList.next_bck; /*-----------------------------------------------------------------*/ /* Break upon reaching non-expired timer. */ /*-----------------------------------------------------------------*/ if (timer->time_due != NetTickCount) break; /*-----------------------------------------------------------------*/ /* Remove from head of timeout list and mark as stopped. */ /*-----------------------------------------------------------------*/ TimeoutList.next_bck = TimeoutList.next_bck->next_bck; TimeoutList.next_bck->next_fwd = &TimeoutList; timer->running = FALSE; /*-----------------------------------------------------------------*/ /* Call timer action routine. */ /*-----------------------------------------------------------------*/ timer->action(timer->object); } /*-------------------------------------------------------------------*/ /* Increment tick counter. */ /*-------------------------------------------------------------------*/ ++NetTickCount;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -