tcptimer.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 93 行
C,V
93 行
head 1.2;
access;
symbols;
locks
dls:1.2; strict;
comment @ * @;
1.2
date 97.09.21.19.29.52; author dls; state Dist;
branches;
next 1.1;
1.1
date 94.01.14.03.51.20; author dls; state v2e1;
branches;
next ;
desc
@@
1.2
log
@pre-3e code
@
text
@/* tcptimer.c - tcptimer */
#include <conf.h>
#include <kernel.h>
#include <network.h>
#include <tcptimer.h>
int tqmutex;
int tqpid;
struct tqent *tqhead;
/*------------------------------------------------------------------------
* tcptimer - TCP timer process
*------------------------------------------------------------------------
*/
PROCESS tcptimer()
{
long now, lastrun; /* times from system clock */
int delta; /* time since last iteration */
struct tqent *tq; /* temporary delta list ptr */
lastrun = ctr100; /* initialize to "now" */
tqmutex = screate(1); /* mutual exclusion semaphore */
tqpid = getpid(); /* record timer process id */
signal(Net.sema); /* start other network processes*/
while (TRUE) {
sleep10(TIMERGRAN); /* real-time delay */
if (tqhead == 0) /* block timer process if delta */
suspend(tqpid); /* list is empty */
wait(tqmutex);
now = ctr100;
delta = now - lastrun; /* compute elapsed time */
/* Note: check for possible clock reset (time moved */
/* backward or delay was over an order of magnitude too */
/* long) */
if (delta < 0 || delta > TIMERGRAN*100)
delta = TIMERGRAN*10; /* estimate the delay */
lastrun = now;
while (tqhead != 0 && tqhead->tq_timeleft <= delta) {
delta -= tqhead->tq_timeleft;
if (pcount(tqhead->tq_port) <= tqhead->tq_portlen)
psend(tqhead->tq_port, tqhead->tq_msg);
tq = tqhead;
tqhead = tqhead->tq_next;
freemem(tq, sizeof(struct tqent));
}
if (tqhead)
tqhead->tq_timeleft -=delta;
signal(tqmutex);
}
}
@
1.1
log
@Initial revision
@
text
@@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?