Put sound into multimedia and rename it to audio because it is "MoreCorrect©"
[reactos.git] / reactos / lib / drivers / oskittcp / include / freebsd / src / sys / sys / socketvar.h
1 /*-
2 * Copyright (c) 1982, 1986, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)socketvar.h 8.1 (Berkeley) 6/2/93
34 */
35
36 #ifndef _SYS_SOCKETVAR_H_
37 #define _SYS_SOCKETVAR_H_
38
39 #include <sys/stat.h> /* for struct stat */
40 #include <sys/filedesc.h> /* for struct filedesc */
41 #include <sys/select.h> /* for struct selinfo */
42
43 /* Warning suppression */
44 struct sockaddr;
45
46 /*
47 * Used to maintain information about processes that wish to be
48 * notified when I/O becomes possible.
49 *
50 * Moved from sys/select.h and replaced with an #include.
51 */
52 struct selinfo {
53 #if defined(OSKIT)
54 struct listener_mgr *si_sel;
55 #endif /* OSKIT */
56 pid_t si_pid; /* process to be notified */
57 short si_flags; /* see below */
58 };
59 #define SI_COLL 0x0001 /* collision occurred */
60
61
62 /*
63 * Kernel structure per socket.
64 * Contains send and receive buffer queues,
65 * handle on protocol and pointer to protocol
66 * private data and error information.
67 */
68 struct socket {
69 short so_type; /* generic type, see socket.h */
70 short so_options; /* from socket call, see socket.h */
71 short so_linger; /* time to linger while closing */
72 short so_state; /* internal state flags SS_*, below */
73 caddr_t so_pcb; /* protocol control block */
74 void *so_connection; /* connection (outside context) */
75 struct protosw *so_proto; /* protocol handle */
76 /*
77 * Variables for connection queueing.
78 * Socket where accepts occur is so_head in all subsidiary sockets.
79 * If so_head is 0, socket is not related to an accept.
80 * For head socket so_q0 queues partially completed connections,
81 * while so_q is a queue of connections ready to be accepted.
82 * If a connection is aborted and it has so_head set, then
83 * it has to be pulled out of either so_q0 or so_q.
84 * We allow connections to queue up based on current queue lengths
85 * and limit on number of queued connections for this socket.
86 */
87 struct socket *so_head; /* back pointer to accept socket */
88 struct socket *so_q0; /* queue of partial connections */
89 struct socket *so_q; /* queue of incoming connections */
90 short so_q0len; /* partials on so_q0 */
91 short so_qlen; /* number of connections on so_q */
92 short so_qlimit; /* max number queued connections */
93 short so_timeo; /* connection timeout */
94 u_short so_error; /* error affecting connection */
95 pid_t so_pgid; /* pgid for signals */
96 u_long so_oobmark; /* chars to oob mark */
97 /*
98 * Variables for socket buffering.
99 */
100 struct sockbuf {
101 u_long sb_cc; /* actual chars in buffer */
102 u_long sb_hiwat; /* max actual char count */
103 u_long sb_mbcnt; /* chars of mbufs used */
104 u_long sb_mbmax; /* max chars of mbufs to use */
105 long sb_lowat; /* low water mark */
106 struct mbuf *sb_mb; /* the mbuf chain */
107 struct selinfo sb_sel; /* process selecting read/write */
108 short sb_flags; /* flags, see below */
109 short sb_timeo; /* timeout for read/write */
110 } so_rcv, so_snd;
111 #define SB_MAX (256*1024) /* default for max chars in sockbuf */
112 #define SB_LOCK 0x01 /* lock on data queue */
113 #define SB_WANT 0x02 /* someone is waiting to lock */
114 #define SB_WAIT 0x04 /* someone is waiting for data/space */
115 #define SB_SEL 0x08 /* someone is selecting */
116 #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
117 #define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
118 #define SB_NOINTR 0x40 /* operations not interruptible */
119
120 caddr_t so_tpcb; /* Wisc. protocol control block XXX */
121 void (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf));
122 caddr_t so_upcallarg; /* Arg for above */
123 };
124
125 /*
126 * Socket state bits.
127 */
128 #define SS_NOFDREF 0x001 /* no file table ref any more */
129 #define SS_ISCONNECTED 0x002 /* socket connected to a peer */
130 #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
131 #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
132 #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
133 #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
134 #define SS_RCVATMARK 0x040 /* at mark on input */
135
136 #define SS_PRIV 0x080 /* privileged for broadcast, raw... */
137 #define SS_NBIO 0x100 /* non-blocking ops */
138 #define SS_ASYNC 0x200 /* async i/o notify */
139 #define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
140
141
142 /*
143 * Macros for sockets and socket buffering.
144 */
145
146 /*
147 * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
148 * This is problematical if the fields are unsigned, as the space might
149 * still be negative (cc > hiwat or mbcnt > mbmax). Should detect
150 * overflow and return 0. Should use "lmin" but it doesn't exist now.
151 */
152 #define sbspace(sb) \
153 ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
154 (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
155
156 /* do we have to send all at once on a socket? */
157 #define sosendallatonce(so) \
158 ((so)->so_proto->pr_flags & PR_ATOMIC)
159
160 /* can we read something from so? */
161 #define soreadable(so) \
162 ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
163 ((so)->so_state & SS_CANTRCVMORE) || \
164 (so)->so_qlen || (so)->so_error)
165
166 /* can we write something to so? */
167 #define sowriteable(so) \
168 ((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
169 (((so)->so_state&SS_ISCONNECTED) || \
170 ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
171 ((so)->so_state & SS_CANTSENDMORE) || \
172 (so)->so_error)
173
174 /* adjust counters in sb reflecting allocation of m */
175 #define sballoc(sb, m) { \
176 (sb)->sb_cc += (m)->m_len; \
177 (sb)->sb_mbcnt += MSIZE; \
178 if ((m)->m_flags & M_EXT) \
179 (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
180 }
181
182 /* adjust counters in sb reflecting freeing of m */
183 #define sbfree(sb, m) { \
184 (sb)->sb_cc -= (m)->m_len; \
185 (sb)->sb_mbcnt -= MSIZE; \
186 if ((m)->m_flags & M_EXT) \
187 (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
188 }
189
190 /*
191 * Set lock on sockbuf sb; sleep if lock is already held.
192 * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
193 * Returns error without lock if sleep is interrupted.
194 */
195 #define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
196 (((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
197 ((sb)->sb_flags |= SB_LOCK), 0)
198
199 /* release lock on sockbuf sb */
200 #define sbunlock(so, sb) { \
201 (sb)->sb_flags &= ~SB_LOCK; \
202 if ((sb)->sb_flags & SB_WANT) { \
203 (sb)->sb_flags &= ~SB_WANT; \
204 wakeup(so, (caddr_t)&(sb)->sb_flags); \
205 } \
206 }
207
208 #define sorwakeup(so) { sowakeup((so), &(so)->so_rcv); \
209 if ((so)->so_upcall) \
210 (*((so)->so_upcall))((so), (so)->so_upcallarg, M_DONTWAIT); \
211 }
212
213 #define sowwakeup(so) sowakeup((so), &(so)->so_snd)
214
215 #ifdef KERNEL
216 extern u_long sb_max;
217 /* to catch callers missing new second argument to sonewconn: */
218 #define sonewconn(head, connstatus) sonewconn1((head), (connstatus))
219 struct socket *sonewconn1 __P((struct socket *head, int connstatus));
220
221 /* strings for sleep message: */
222 extern char netio[], netcon[], netcls[];
223
224 /*
225 * File operations on sockets.
226 */
227 int soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred));
228 int soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred));
229 int soo_ioctl __P((struct file *fp, int com, caddr_t data, struct proc *p));
230 int soo_select __P((struct file *fp, int which, struct proc *p));
231 int soo_close __P((struct file *fp, struct proc *p));
232 int soo_stat __P((struct socket *, struct stat *));
233
234 /*
235 * From uipc_socket and friends
236 */
237 void soqinsque __P((struct socket *, struct socket *, int));
238 void sowakeup __P((struct socket *, struct sockbuf *));
239 void socantrcvmore __P((struct socket *));
240 void socantsendmore __P((struct socket *));
241 void sbrelease __P((struct sockbuf *));
242 void sbappend __P((struct sockbuf *, struct mbuf *));
243 void sbappendrecord __P((struct sockbuf *, struct mbuf *));
244 int sbappendcontrol __P((struct sockbuf *, struct mbuf *, struct mbuf *));
245 int sbappendaddr __P((struct sockbuf *, struct sockaddr *, struct mbuf *, struct mbuf *));
246 void sbdroprecord __P((struct sockbuf *));
247 void sbcompress __P((struct sockbuf *, struct mbuf *, struct mbuf *));
248 void sbflush __P((struct sockbuf *));
249 int sbreserve __P((struct sockbuf *,u_long));
250 int soreserve __P((struct socket *,u_long,u_long));
251 int sb_lock __P((struct sockbuf *));
252 int sbwait __P((struct sockbuf *));
253 void sbdrop __P((struct sockbuf *, int));
254 void sofree __P((struct socket *));
255 void sorflush __P((struct socket *));
256 int soqremque __P((struct socket *,int));
257 int soabort __P((struct socket *));
258 void soisdisconnected __P((struct socket *));
259 void soisconnected __P((struct socket *));
260 void soisconnecting __P((struct socket *));
261 void soisdisconnecting __P((struct socket *));
262 void sohasoutofband __P((struct socket *));
263 int sodisconnect __P((struct socket *));
264 int sosend __P((struct socket *,struct mbuf *, struct uio *, struct mbuf *, struct mbuf *, int));
265 int socreate __P((int, struct socket **,int,int));
266 int getsock __P((struct filedesc *,int,struct file **));
267 int sockargs __P((struct mbuf **,caddr_t,int,int));
268 int sobind __P((struct socket *,struct mbuf *));
269 int solisten __P((struct socket *,int));
270 int soaccept __P((struct socket *,struct mbuf *));
271 int soconnect __P((struct socket *,struct mbuf *));
272 int soconnect2 __P((struct socket *,struct socket *));
273 int soclose __P((struct socket *));
274 int soshutdown __P((struct socket *,int));
275 int soreceive __P((struct socket *,struct mbuf **,struct uio *,struct mbuf **,struct mbuf **,int *));
276 int sosetopt __P((struct socket *,int, int, struct mbuf *));
277 int sogetopt __P((struct socket *,int, int, struct mbuf **));
278 #endif
279
280 #endif