]>
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 | * dspStatus.c | |
30 | * | |
31 | * From Mike Shoemaker v01.04 06/15/90 mbs | |
32 | * Modified for MP, 1996 by Tuyen Nguyen | |
33 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
34 | */ | |
35 | ||
36 | #include <sys/errno.h> | |
37 | #include <sys/types.h> | |
38 | #include <sys/param.h> | |
39 | #include <machine/spl.h> | |
40 | #include <sys/systm.h> | |
41 | #include <sys/kernel.h> | |
42 | #include <sys/proc.h> | |
43 | #include <sys/filedesc.h> | |
44 | #include <sys/fcntl.h> | |
45 | #include <sys/mbuf.h> | |
46 | #include <sys/socket.h> | |
47 | ||
48 | #include <netat/sysglue.h> | |
49 | #include <netat/appletalk.h> | |
50 | #include <netat/at_pcb.h> | |
51 | #include <netat/adsp.h> | |
52 | #include <netat/adsp_internal.h> | |
53 | ||
54 | /* | |
55 | * calcSendFree | |
56 | * | |
57 | * INPUTS: | |
58 | * sp ADSP Stream | |
59 | * OUTPUTS: | |
60 | * # of bytes avail in local send queue | |
61 | */ | |
62 | int CalcSendQFree(sp) /* (CCBPtr sp) */ | |
63 | CCBPtr sp; | |
64 | { | |
65 | int bytes; | |
66 | ||
67 | bytes = calcSendQ(sp); | |
68 | bytes = sp->sbuflen - bytes; | |
69 | ||
70 | if (bytes < 0) | |
71 | return 0; | |
72 | return bytes; | |
73 | } | |
74 | ||
75 | calcSendQ(sp) | |
76 | CCBPtr sp; | |
77 | { | |
78 | register gbuf_t *mp; | |
79 | int bytes = 0; | |
80 | ||
81 | if (sp->sData) { /* There is data in buffer */ | |
82 | if (mp = sp->sbuf_mb) { | |
83 | do { | |
84 | bytes += gbuf_msgsize(mp); | |
85 | mp = gbuf_next(mp); | |
86 | } while (mp); | |
87 | } | |
88 | if (mp = sp->csbuf_mb) | |
89 | bytes += gbuf_msgsize(mp); | |
90 | } | |
91 | return bytes; | |
92 | } | |
93 | ||
94 | /* | |
95 | * dspStatus | |
96 | * | |
97 | * INPUTS: | |
98 | * --> ccbRefNum refnum of connection end | |
99 | * | |
100 | * OUTPUTS: | |
101 | * <-- statusCCB Pointer to the connection control block | |
102 | * <-- sendQPending bytes waiting to be sent or acknowledged | |
103 | * <-- sendQFree available buffer in bytes of send queue | |
104 | * <-- recvQPending bytes waiting to be read from queue | |
105 | * <-- recvQFree available buffer in bytes of receive queue | |
106 | * | |
107 | * ERRORS: | |
108 | * errRefNum bad connection refnum | |
109 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | |
110 | */ | |
111 | int adspStatus(sp, pb) /* (DSPPBPtr pb) */ | |
112 | CCBPtr sp; | |
113 | register struct adspcmd *pb; | |
114 | { | |
115 | short err; | |
116 | short bytes; | |
8f6c56a5 | 117 | int s; |
1c79356b A |
118 | |
119 | if (sp == 0) { | |
120 | pb->ioResult = errRefNum; | |
121 | return EINVAL; | |
122 | } | |
123 | ||
124 | pb->u.statusParams.ccbPtr = (TPCCB)sp; | |
8f6c56a5 | 125 | ATDISABLE(s, sp->lock); |
1c79356b A |
126 | |
127 | /* | |
128 | * pending bytes in send queue | |
129 | */ | |
130 | if (sp->sData) | |
131 | bytes = calcSendQ(sp); | |
132 | else | |
133 | bytes = 0; | |
134 | pb->u.statusParams.sendQPending = bytes; | |
135 | ||
136 | /* available buffer space in send queue */ | |
137 | pb->u.statusParams.sendQFree = CalcSendQFree(sp); | |
138 | ||
139 | /* | |
140 | * pending bytes in recv queue | |
141 | */ | |
142 | if (sp->rData) | |
143 | bytes = calcRecvQ(sp); | |
144 | else | |
145 | bytes = 0; | |
146 | pb->u.statusParams.recvQPending = bytes; | |
147 | ||
148 | /* available buffer space in receive queue */ | |
149 | pb->u.statusParams.recvQFree = CalcRecvWdw(sp); | |
150 | ||
8f6c56a5 | 151 | ATENABLE(s, sp->lock); |
1c79356b A |
152 | pb->ioResult = 0; |
153 | adspioc_ack(0, pb->ioc, pb->gref); | |
154 | return 0; | |
155 | ||
156 | } |