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