]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1990, 1996-1998 Apple Computer, Inc. | |
24 | * All Rights Reserved. | |
25 | */ | |
26 | ||
27 | /* | |
28 | * Timer.c | |
29 | * | |
30 | * From v01.12 06/22/90 mbs | |
31 | * Modified for MP, 1996 by Tuyen Nguyen | |
32 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
33 | */ | |
34 | ||
35 | #include <sys/errno.h> | |
36 | #include <sys/types.h> | |
37 | #include <sys/param.h> | |
38 | #include <machine/spl.h> | |
39 | #include <sys/systm.h> | |
40 | #include <sys/kernel.h> | |
41 | #include <sys/proc.h> | |
42 | #include <sys/filedesc.h> | |
43 | #include <sys/fcntl.h> | |
44 | #include <sys/mbuf.h> | |
45 | #include <sys/socket.h> | |
46 | #include <sys/time.h> | |
47 | ||
48 | #include <netat/sysglue.h> | |
49 | #include <netat/appletalk.h> | |
50 | #include <netat/at_pcb.h> | |
51 | #include <netat/debug.h> | |
52 | #include <netat/adsp.h> | |
53 | #include <netat/adsp_internal.h> | |
54 | ||
55 | /* | |
56 | * TrashSession | |
57 | * | |
58 | * Cleanly abort a session that might be open. Called if probe timer expires, | |
59 | * or from AppleTalk event handler (close or network gone away) | |
60 | * | |
61 | * Only call if the session is active (I.e. not for closed or listeners) | |
62 | * | |
63 | * INPUTS: | |
64 | * session pointer | |
65 | * OUTPUTS: | |
66 | * none | |
67 | */ | |
68 | void TrashSession(sp) /* (CCBPtr sp) */ | |
69 | CCBPtr sp; | |
70 | { | |
71 | int s; | |
72 | ||
73 | ATDISABLE(s, sp->lock); | |
74 | sp->userFlags |= eTearDown; | |
75 | sp->removing = 1; | |
76 | sp->state = sClosed; | |
77 | ATENABLE(s, sp->lock); | |
78 | ||
79 | DoClose(sp, errAborted, 1); | |
80 | } | |
81 | ||
82 | ||
83 | /* | |
84 | * DoTimerElem | |
85 | * | |
86 | * INPUTS: | |
87 | * | |
88 | * OUTPUTS: | |
89 | * | |
90 | */ | |
91 | void DoTimerElem(t) /* (TimerElemPtr t) */ | |
92 | TimerElemPtr t; | |
93 | { | |
94 | CCBPtr sp; | |
95 | int s; | |
96 | ||
97 | sp = (CCBPtr)((Ptr)t - t->type); /* Recover stream pointer for this guy */ | |
98 | ATDISABLE(s, sp->lock); | |
99 | ||
100 | if (t->type == kFlushTimerType) { /* flush write data time just fired */ | |
101 | if (sp->sData) { /* If there's any data, flush it. */ | |
102 | sp->writeFlush = 1; | |
103 | goto send; | |
104 | } | |
105 | } else if (t->type == kRetryTimerType) { | |
106 | if (sp->waitingAck) { | |
107 | ||
108 | sp->waitingAck = 0; | |
109 | sp->sendSeq = sp->firstRtmtSeq; | |
110 | sp->pktSendCnt = 0; | |
111 | sp->resentData = 1; /* Had to resend data */ | |
112 | sp->noXmitFlow = 1; /* Don't incr. max packets. */ | |
113 | ||
114 | if ((sp->pktSendMax /= 2) == 0) /* Back off on max # packets | |
115 | * sent */ | |
116 | sp->pktSendMax = 1; | |
117 | ||
118 | if ((sp->roundTrip *= 2) > sp->probeInterval) | |
119 | sp->roundTrip = sp->probeInterval; | |
120 | sp->rtmtInterval = sp->roundTrip + ((short)2 * | |
121 | (short)sp->deviation); | |
122 | goto send; | |
123 | } | |
124 | } else if (t->type == kAttnTimerType) { | |
125 | if (sp->sapb) { /* Unacknowledged attn pkt */ | |
126 | sp->sendAttnData = 1; | |
127 | goto send; | |
128 | } | |
129 | } else if (t->type == kResetTimerType) { | |
130 | if (sp->frpb) { /* Unacknowledged forward reset */ | |
131 | sp->sendCtl |= B_CTL_FRESET; | |
132 | goto send; | |
133 | } | |
134 | } else if (t->type == kProbeTimerType) { | |
135 | if (sp->state == sOpen || sp->state == sClosing) { | |
136 | if (--sp->probeCntr == 0) { /* Connection died */ | |
137 | ATENABLE(s, sp->lock); | |
138 | TrashSession(sp); | |
139 | return; | |
140 | } else { | |
141 | InsertTimerElem(&adspGlobal.slowTimers, &sp->ProbeTimer, | |
142 | sp->probeInterval); | |
143 | sp->sendCtl |= B_CTL_PROBE; | |
144 | goto send; | |
145 | } | |
146 | } else if (sp->state == sOpening) { | |
147 | if ((sp->openState == O_STATE_OPENWAIT) || | |
148 | (sp->openState == O_STATE_ESTABLISHED)) | |
149 | { | |
150 | if (--sp->openRetrys == 0) { /* Oops, didn't open */ | |
151 | sp->state = sClosed; | |
152 | ATENABLE(s, sp->lock); | |
153 | DoClose(sp, errOpening, 1); | |
154 | return; | |
155 | } /* open failed */ | |
156 | else /* Send packet again */ | |
157 | { | |
158 | sp->sendCtl |= (sp->openState == O_STATE_OPENWAIT) ? | |
159 | B_CTL_OREQ : B_CTL_OREQACK; | |
160 | goto send; | |
161 | } | |
162 | } /* we're opening */ | |
163 | } | |
164 | } | |
165 | ||
166 | else { | |
167 | dPrintf(D_M_ADSP, D_L_ERROR, ("DoTimerElem:Unknown timer type!\n")); | |
168 | } | |
169 | ||
170 | ATENABLE(s, sp->lock); | |
171 | return; | |
172 | ||
173 | send: | |
174 | ATENABLE(s, sp->lock); | |
175 | CheckSend(sp); | |
176 | } | |
177 | ||
178 | void TimerTick_funnel() | |
179 | { | |
180 | thread_funnel_set(network_flock, TRUE); | |
181 | TimerTick(); | |
182 | thread_funnel_set(network_flock, FALSE); | |
183 | } | |
184 | ||
185 | static StopTimer; | |
186 | ||
187 | /* | |
188 | * TimerTick | |
189 | * | |
190 | * Called 6 times per second | |
191 | * INPUTS: | |
192 | * | |
193 | * OUTPUTS: | |
194 | * | |
195 | */ | |
196 | void TimerTick() /* (void) */ | |
197 | { | |
198 | ||
199 | if (StopTimer) { | |
200 | return; | |
201 | } | |
202 | TimerQueueTick(&adspGlobal.slowTimers); | |
203 | TimerQueueTick(&adspGlobal.fastTimers); | |
204 | timeout(TimerTick_funnel, (caddr_t)0, HZ/6); | |
205 | } | |
206 | ||
207 | void TimerStop() | |
208 | { | |
209 | StopTimer = 1; | |
210 | untimeout(TimerTick_funnel, (caddr_t) 0); | |
211 | } |