|
|
1.1 root 1: #include "u.h"
2: #include "../port/lib.h"
3: #include "mem.h"
4: #include "dat.h"
5: #include "fns.h"
6: #include "../port/error.h"
7: #include "arp.h"
8: #include "../port/ipdat.h"
9:
10: static Timer *timers; /* List of active timers */
11: static QLock tl; /* Protect timer list */
12: static Rendez Tcpack;
13: Rendez tcpflowr;
14:
15: static void
16: deltimer(Timer *t)
17: {
18: if(timers == t)
19: timers = t->next;
20:
21: if(t->next)
22: t->next->prev = t->prev;
23:
24: if(t->prev)
25: t->prev->next = t->next;
26: }
27:
28: /*
29: * Poke each tcp connection to recompute window size and
30: * acknowledgement timer
31: */
32:
33: void
34: tcpflow(void *x)
35: {
36: Ipifc *ifc;
37: Ipconv *cp, **p, **etab;
38:
39: ifc = x;
40: etab = &ifc->conv[Nipconv];
41:
42: for(;;) {
43: sleep(&tcpflowr, return0, 0);
44:
45: for(p = ifc->conv; p < etab; p++) {
46: cp = *p;
47: if(cp == 0)
48: break;
49: if(cp->readq && cp->ref != 0 && !QFULL(cp->readq->next)) {
50: tcprcvwin(cp);
51: tcpacktimer(cp);
52: }
53: }
54: }
55: }
56:
57: void
58: tcpackproc(void *junk)
59: {
60: Timer *t, *tp, *timeo;
61:
62: USED(junk);
63: for(;;) {
64: timeo = 0;
65:
66: qlock(&tl);
67: for(t = timers;t != 0; t = tp) {
68: tp = t->next;
69: if(t->state == TimerON) {
70: t->count--;
71: if(t->count == 0) {
72: deltimer(t);
73: t->state = TimerDONE;
74: t->next = timeo;
75: timeo = t;
76: }
77: }
78: }
79: qunlock(&tl);
80:
81: for(;;) {
82: t = timeo;
83: if(t == 0)
84: break;
85:
86: timeo = t->next;
87: if(t->state == TimerDONE)
88: if(t->func)
89: (*t->func)(t->arg);
90: }
91: tsleep(&Tcpack, return0, 0, MSPTICK);
92: }
93: }
94:
95: void
96: tcpgo(Timer *t)
97: {
98: if(t == 0 || t->start == 0)
99: return;
100:
101: qlock(&tl);
102: t->count = t->start;
103: if(t->state != TimerON) {
104: t->state = TimerON;
105: t->prev = 0;
106: t->next = timers;
107: if(t->next)
108: t->next->prev = t;
109: timers = t;
110: }
111: qunlock(&tl);
112: }
113:
114: void
115: tcphalt(Timer *t)
116: {
117: if(t == 0)
118: return;
119:
120: qlock(&tl);
121: if(t->state == TimerON)
122: deltimer(t);
123: t->state = TimerOFF;
124: qunlock(&tl);
125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.