]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Status.c
1f4158d2713140f299c982b4fbad46453016e3af
[apple/xnu.git] / bsd / netat / adsp_Status.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * dspStatus.c
25 *
26 * From Mike Shoemaker v01.04 06/15/90 mbs
27 * Modified for MP, 1996 by Tuyen Nguyen
28 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
29 */
30
31 #include <sys/errno.h>
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <machine/spl.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/proc.h>
38 #include <sys/filedesc.h>
39 #include <sys/fcntl.h>
40 #include <sys/mbuf.h>
41 #include <sys/socket.h>
42
43 #include <netat/sysglue.h>
44 #include <netat/appletalk.h>
45 #include <netat/at_pcb.h>
46 #include <netat/adsp.h>
47 #include <netat/adsp_internal.h>
48
49 /*
50 * calcSendFree
51 *
52 * INPUTS:
53 * sp ADSP Stream
54 * OUTPUTS:
55 * # of bytes avail in local send queue
56 */
57 int CalcSendQFree(sp) /* (CCBPtr sp) */
58 CCBPtr sp;
59 {
60 int bytes;
61
62 bytes = calcSendQ(sp);
63 bytes = sp->sbuflen - bytes;
64
65 if (bytes < 0)
66 return 0;
67 return bytes;
68 }
69
70 calcSendQ(sp)
71 CCBPtr sp;
72 {
73 register gbuf_t *mp;
74 int bytes = 0;
75
76 if (sp->sData) { /* There is data in buffer */
77 if (mp = sp->sbuf_mb) {
78 do {
79 bytes += gbuf_msgsize(mp);
80 mp = gbuf_next(mp);
81 } while (mp);
82 }
83 if (mp = sp->csbuf_mb)
84 bytes += gbuf_msgsize(mp);
85 }
86 return bytes;
87 }
88
89 /*
90 * dspStatus
91 *
92 * INPUTS:
93 * --> ccbRefNum refnum of connection end
94 *
95 * OUTPUTS:
96 * <-- statusCCB Pointer to the connection control block
97 * <-- sendQPending bytes waiting to be sent or acknowledged
98 * <-- sendQFree available buffer in bytes of send queue
99 * <-- recvQPending bytes waiting to be read from queue
100 * <-- recvQFree available buffer in bytes of receive queue
101 *
102 * ERRORS:
103 * errRefNum bad connection refnum
104 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
105 */
106 int adspStatus(sp, pb) /* (DSPPBPtr pb) */
107 CCBPtr sp;
108 register struct adspcmd *pb;
109 {
110 short err;
111 short bytes;
112 int s;
113
114 if (sp == 0) {
115 pb->ioResult = errRefNum;
116 return EINVAL;
117 }
118
119 pb->u.statusParams.ccbPtr = (TPCCB)sp;
120 ATDISABLE(s, sp->lock);
121
122 /*
123 * pending bytes in send queue
124 */
125 if (sp->sData)
126 bytes = calcSendQ(sp);
127 else
128 bytes = 0;
129 pb->u.statusParams.sendQPending = bytes;
130
131 /* available buffer space in send queue */
132 pb->u.statusParams.sendQFree = CalcSendQFree(sp);
133
134 /*
135 * pending bytes in recv queue
136 */
137 if (sp->rData)
138 bytes = calcRecvQ(sp);
139 else
140 bytes = 0;
141 pb->u.statusParams.recvQPending = bytes;
142
143 /* available buffer space in receive queue */
144 pb->u.statusParams.recvQFree = CalcRecvWdw(sp);
145
146 ATENABLE(s, sp->lock);
147 pb->ioResult = 0;
148 adspioc_ack(0, pb->ioc, pb->gref);
149 return 0;
150
151 }