]>
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_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1990, 1996-1998 Apple Computer, Inc.
24 * All Rights Reserved.
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.
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>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
45 #include <sys/socket.h>
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>
60 * Cleanly abort a session that might be open. Called if probe timer expires,
61 * or from AppleTalk event handler (close or network gone away)
63 * Only call if the session is active (I.e. not for closed or listeners)
70 void TrashSession(sp
) /* (CCBPtr sp) */
75 ATDISABLE(s
, sp
->lock
);
76 sp
->userFlags
|= eTearDown
;
79 ATENABLE(s
, sp
->lock
);
81 DoClose(sp
, errAborted
, 1);
93 void DoTimerElem(t
) /* (TimerElemPtr t) */
99 sp
= (CCBPtr
)((Ptr
)t
- t
->type
); /* Recover stream pointer for this guy */
100 ATDISABLE(s
, sp
->lock
);
102 if (t
->type
== kFlushTimerType
) { /* flush write data time just fired */
103 if (sp
->sData
) { /* If there's any data, flush it. */
107 } else if (t
->type
== kRetryTimerType
) {
108 if (sp
->waitingAck
) {
111 sp
->sendSeq
= sp
->firstRtmtSeq
;
113 sp
->resentData
= 1; /* Had to resend data */
114 sp
->noXmitFlow
= 1; /* Don't incr. max packets. */
116 if ((sp
->pktSendMax
/= 2) == 0) /* Back off on max # packets
120 if ((sp
->roundTrip
*= 2) > sp
->probeInterval
)
121 sp
->roundTrip
= sp
->probeInterval
;
122 sp
->rtmtInterval
= sp
->roundTrip
+ ((short)2 *
123 (short)sp
->deviation
);
126 } else if (t
->type
== kAttnTimerType
) {
127 if (sp
->sapb
) { /* Unacknowledged attn pkt */
128 sp
->sendAttnData
= 1;
131 } else if (t
->type
== kResetTimerType
) {
132 if (sp
->frpb
) { /* Unacknowledged forward reset */
133 sp
->sendCtl
|= B_CTL_FRESET
;
136 } else if (t
->type
== kProbeTimerType
) {
137 if (sp
->state
== sOpen
|| sp
->state
== sClosing
) {
138 if (--sp
->probeCntr
== 0) { /* Connection died */
139 ATENABLE(s
, sp
->lock
);
143 InsertTimerElem(&adspGlobal
.slowTimers
, &sp
->ProbeTimer
,
145 sp
->sendCtl
|= B_CTL_PROBE
;
148 } else if (sp
->state
== sOpening
) {
149 if ((sp
->openState
== O_STATE_OPENWAIT
) ||
150 (sp
->openState
== O_STATE_ESTABLISHED
))
152 if (--sp
->openRetrys
== 0) { /* Oops, didn't open */
154 ATENABLE(s
, sp
->lock
);
155 DoClose(sp
, errOpening
, 1);
158 else /* Send packet again */
160 sp
->sendCtl
|= (sp
->openState
== O_STATE_OPENWAIT
) ?
161 B_CTL_OREQ
: B_CTL_OREQACK
;
164 } /* we're opening */
169 dPrintf(D_M_ADSP
, D_L_ERROR
, ("DoTimerElem:Unknown timer type!\n"));
172 ATENABLE(s
, sp
->lock
);
176 ATENABLE(s
, sp
->lock
);
180 void TimerTick_funnel(void *arg
)
192 * Called 6 times per second
198 void TimerTick() /* (void) */
204 TimerQueueTick(&adspGlobal
.slowTimers
);
205 TimerQueueTick(&adspGlobal
.fastTimers
);
206 timeout(TimerTick_funnel
, (caddr_t
)0, HZ
/6);
212 untimeout(TimerTick_funnel
, (caddr_t
) 0);