]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Status.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / netat / adsp_Status.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. 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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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;
117
118 if (sp == 0) {
119 pb->ioResult = errRefNum;
120 return EINVAL;
121 }
122
123 pb->u.statusParams.ccbPtr = (TPCCB)sp;
124
125 /*
126 * pending bytes in send queue
127 */
128 if (sp->sData)
129 bytes = calcSendQ(sp);
130 else
131 bytes = 0;
132 pb->u.statusParams.sendQPending = bytes;
133
134 /* available buffer space in send queue */
135 pb->u.statusParams.sendQFree = CalcSendQFree(sp);
136
137 /*
138 * pending bytes in recv queue
139 */
140 if (sp->rData)
141 bytes = calcRecvQ(sp);
142 else
143 bytes = 0;
144 pb->u.statusParams.recvQPending = bytes;
145
146 /* available buffer space in receive queue */
147 pb->u.statusParams.recvQFree = CalcRecvWdw(sp);
148
149 pb->ioResult = 0;
150 adspioc_ack(0, pb->ioc, pb->gref);
151 return 0;
152
153 }