]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Timer.c
73012cb755a4423d4b8dbb1c66a31a1d831f4251
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1990, 1996-1998 Apple Computer, Inc.
32 * All Rights Reserved.
38 * From v01.12 06/22/90 mbs
39 * Modified for MP, 1996 by Tuyen Nguyen
40 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
43 #include <sys/errno.h>
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <machine/spl.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
50 #include <sys/filedesc.h>
51 #include <sys/fcntl.h>
53 #include <sys/socket.h>
56 #include <netat/sysglue.h>
57 #include <netat/appletalk.h>
58 #include <netat/at_pcb.h>
59 #include <netat/debug.h>
60 #include <netat/adsp.h>
61 #include <netat/adsp_internal.h>
68 * Cleanly abort a session that might be open. Called if probe timer expires,
69 * or from AppleTalk event handler (close or network gone away)
71 * Only call if the session is active (I.e. not for closed or listeners)
78 void TrashSession(sp
) /* (CCBPtr sp) */
83 ATDISABLE(s
, sp
->lock
);
84 sp
->userFlags
|= eTearDown
;
87 ATENABLE(s
, sp
->lock
);
89 DoClose(sp
, errAborted
, 1);
101 void DoTimerElem(t
) /* (TimerElemPtr t) */
107 sp
= (CCBPtr
)((Ptr
)t
- t
->type
); /* Recover stream pointer for this guy */
108 ATDISABLE(s
, sp
->lock
);
110 if (t
->type
== kFlushTimerType
) { /* flush write data time just fired */
111 if (sp
->sData
) { /* If there's any data, flush it. */
115 } else if (t
->type
== kRetryTimerType
) {
116 if (sp
->waitingAck
) {
119 sp
->sendSeq
= sp
->firstRtmtSeq
;
121 sp
->resentData
= 1; /* Had to resend data */
122 sp
->noXmitFlow
= 1; /* Don't incr. max packets. */
124 if ((sp
->pktSendMax
/= 2) == 0) /* Back off on max # packets
128 if ((sp
->roundTrip
*= 2) > sp
->probeInterval
)
129 sp
->roundTrip
= sp
->probeInterval
;
130 sp
->rtmtInterval
= sp
->roundTrip
+ ((short)2 *
131 (short)sp
->deviation
);
134 } else if (t
->type
== kAttnTimerType
) {
135 if (sp
->sapb
) { /* Unacknowledged attn pkt */
136 sp
->sendAttnData
= 1;
139 } else if (t
->type
== kResetTimerType
) {
140 if (sp
->frpb
) { /* Unacknowledged forward reset */
141 sp
->sendCtl
|= B_CTL_FRESET
;
144 } else if (t
->type
== kProbeTimerType
) {
145 if (sp
->state
== sOpen
|| sp
->state
== sClosing
) {
146 if (--sp
->probeCntr
== 0) { /* Connection died */
147 ATENABLE(s
, sp
->lock
);
151 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
153 sp
->sendCtl
|= B_CTL_PROBE
;
156 } else if (sp
->state
== sOpening
) {
157 if ((sp
->openState
== O_STATE_OPENWAIT
) ||
158 (sp
->openState
== O_STATE_ESTABLISHED
))
160 if (--sp
->openRetrys
== 0) { /* Oops, didn't open */
162 ATENABLE(s
, sp
->lock
);
163 DoClose(sp
, errOpening
, 1);
166 else /* Send packet again */
168 sp
->sendCtl
|= (sp
->openState
== O_STATE_OPENWAIT
) ?
169 B_CTL_OREQ
: B_CTL_OREQACK
;
172 } /* we're opening */
177 dPrintf(D_M_ADSP
, D_L_ERROR
, ("DoTimerElem:Unknown timer type!\n"));
180 ATENABLE(s
, sp
->lock
);
184 ATENABLE(s
, sp
->lock
);
188 void TimerTick_funnel(void *arg
)
200 * Called 6 times per second
206 void TimerTick() /* (void) */
212 TimerQueueTick(&adspGlobal
.slowTimers
);
213 TimerQueueTick(&adspGlobal
.fastTimers
);
214 timeout(TimerTick_funnel
, (caddr_t
)0, HZ
/6);
220 untimeout(TimerTick_funnel
, (caddr_t
) 0);