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