]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Timer.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1990, 1996-1998 Apple Computer, Inc.
30 * All Rights Reserved.
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.
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>
48 #include <sys/filedesc.h>
49 #include <sys/fcntl.h>
51 #include <sys/socket.h>
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>
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)
69 * Only call if the session is active (I.e. not for closed or listeners)
76 void TrashSession(sp
) /* (CCBPtr sp) */
81 ATDISABLE(s
, sp
->lock
);
82 sp
->userFlags
|= eTearDown
;
85 ATENABLE(s
, sp
->lock
);
87 DoClose(sp
, errAborted
, 1);
99 void DoTimerElem(t
) /* (TimerElemPtr t) */
105 sp
= (CCBPtr
)((Ptr
)t
- t
->type
); /* Recover stream pointer for this guy */
106 ATDISABLE(s
, sp
->lock
);
108 if (t
->type
== kFlushTimerType
) { /* flush write data time just fired */
109 if (sp
->sData
) { /* If there's any data, flush it. */
113 } else if (t
->type
== kRetryTimerType
) {
114 if (sp
->waitingAck
) {
117 sp
->sendSeq
= sp
->firstRtmtSeq
;
119 sp
->resentData
= 1; /* Had to resend data */
120 sp
->noXmitFlow
= 1; /* Don't incr. max packets. */
122 if ((sp
->pktSendMax
/= 2) == 0) /* Back off on max # packets
126 if ((sp
->roundTrip
*= 2) > sp
->probeInterval
)
127 sp
->roundTrip
= sp
->probeInterval
;
128 sp
->rtmtInterval
= sp
->roundTrip
+ ((short)2 *
129 (short)sp
->deviation
);
132 } else if (t
->type
== kAttnTimerType
) {
133 if (sp
->sapb
) { /* Unacknowledged attn pkt */
134 sp
->sendAttnData
= 1;
137 } else if (t
->type
== kResetTimerType
) {
138 if (sp
->frpb
) { /* Unacknowledged forward reset */
139 sp
->sendCtl
|= B_CTL_FRESET
;
142 } else if (t
->type
== kProbeTimerType
) {
143 if (sp
->state
== sOpen
|| sp
->state
== sClosing
) {
144 if (--sp
->probeCntr
== 0) { /* Connection died */
145 ATENABLE(s
, sp
->lock
);
149 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
151 sp
->sendCtl
|= B_CTL_PROBE
;
154 } else if (sp
->state
== sOpening
) {
155 if ((sp
->openState
== O_STATE_OPENWAIT
) ||
156 (sp
->openState
== O_STATE_ESTABLISHED
))
158 if (--sp
->openRetrys
== 0) { /* Oops, didn't open */
160 ATENABLE(s
, sp
->lock
);
161 DoClose(sp
, errOpening
, 1);
164 else /* Send packet again */
166 sp
->sendCtl
|= (sp
->openState
== O_STATE_OPENWAIT
) ?
167 B_CTL_OREQ
: B_CTL_OREQACK
;
170 } /* we're opening */
175 dPrintf(D_M_ADSP
, D_L_ERROR
, ("DoTimerElem:Unknown timer type!\n"));
178 ATENABLE(s
, sp
->lock
);
182 ATENABLE(s
, sp
->lock
);
186 void TimerTick_funnel(void *arg
)
198 * Called 6 times per second
204 void TimerTick() /* (void) */
210 TimerQueueTick(&adspGlobal
.slowTimers
);
211 TimerQueueTick(&adspGlobal
.fastTimers
);
212 timeout(TimerTick_funnel
, (caddr_t
)0, HZ
/6);
218 untimeout(TimerTick_funnel
, (caddr_t
) 0);