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