|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ ! 26: /*- ! 27: * Copyright (c) 1982, 1986, 1990, 1993 ! 28: * The Regents of the University of California. All rights reserved. ! 29: * ! 30: * Redistribution and use in source and binary forms, with or without ! 31: * modification, are permitted provided that the following conditions ! 32: * are met: ! 33: * 1. Redistributions of source code must retain the above copyright ! 34: * notice, this list of conditions and the following disclaimer. ! 35: * 2. Redistributions in binary form must reproduce the above copyright ! 36: * notice, this list of conditions and the following disclaimer in the ! 37: * documentation and/or other materials provided with the distribution. ! 38: * 3. All advertising materials mentioning features or use of this software ! 39: * must display the following acknowledgement: ! 40: * This product includes software developed by the University of ! 41: * California, Berkeley and its contributors. ! 42: * 4. Neither the name of the University nor the names of its contributors ! 43: * may be used to endorse or promote products derived from this software ! 44: * without specific prior written permission. ! 45: * ! 46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 56: * SUCH DAMAGE. ! 57: * ! 58: * @(#)socketvar.h 8.3 (Berkeley) 2/19/95 ! 59: */ ! 60: ! 61: #ifndef _SYS_SOCKETVAR_H_ ! 62: #define _SYS_SOCKETVAR_H_ ! 63: ! 64: #include <sys/select.h> /* for struct selinfo */ ! 65: #include <sys/queue.h> ! 66: #include <sys/ev.h> ! 67: /* ! 68: * Hacks to get around compiler bitching ! 69: */ ! 70: struct mbuf; ! 71: struct socket; ! 72: struct uio; ! 73: struct sockbuf; ! 74: struct sockaddr; ! 75: ! 76: #define SOCKET_CACHE_ON ! 77: #define SO_CACHE_FLUSH_INTERVAL 1 /* Seconds */ ! 78: #define SO_CACHE_TIME_LIMIT (120/SO_CACHE_FLUSH_INTERVAL) /* Seconds */ ! 79: #define SO_CACHE_MAX_FREE_BATCH 50 ! 80: #define MAX_CACHED_SOCKETS 60000 ! 81: #define TEMPDEBUG 0 ! 82: ! 83: /* ! 84: * Kernel structure per socket. ! 85: * Contains send and receive buffer queues, ! 86: * handle on protocol and pointer to protocol ! 87: * private data and error information. ! 88: */ ! 89: struct socket { ! 90: short so_type; /* generic type, see socket.h */ ! 91: short so_options; /* from socket call, see socket.h */ ! 92: short so_linger; /* time to linger while closing */ ! 93: short so_state; /* internal state flags SS_*, below */ ! 94: caddr_t so_pcb; /* protocol control block */ ! 95: struct protosw *so_proto; /* protocol handle */ ! 96: /* ! 97: * Variables for connection queueing. ! 98: * Socket where accepts occur is so_head in all subsidiary sockets. ! 99: * If so_head is 0, socket is not related to an accept. ! 100: * For head socket so_q0 queues partially completed connections, ! 101: * while so_q is a queue of connections ready to be accepted. ! 102: * If a connection is aborted and it has so_head set, then ! 103: * it has to be pulled out of either so_q0 or so_q. ! 104: * We allow connections to queue up based on current queue lengths ! 105: * and limit on number of queued connections for this socket. ! 106: */ ! 107: struct socket *so_head; /* back pointer to accept socket */ ! 108: struct socket *so_q0; /* queue of partial connections */ ! 109: struct socket *so_q; /* queue of incoming connections */ ! 110: short so_q0len; /* partials on so_q0 */ ! 111: short so_qlen; /* number of connections on so_q */ ! 112: short so_qlimit; /* max number queued connections */ ! 113: short so_timeo; /* connection timeout */ ! 114: u_short so_error; /* error affecting connection */ ! 115: pid_t so_pgid; /* pgid for signals */ ! 116: u_long so_oobmark; /* chars to oob mark */ ! 117: /* ! 118: * Variables for socket buffering. ! 119: */ ! 120: struct sockbuf { ! 121: u_long sb_cc; /* actual chars in buffer */ ! 122: u_long sb_hiwat; /* max actual char count */ ! 123: u_long sb_mbcnt; /* chars of mbufs used */ ! 124: u_long sb_mbmax; /* max chars of mbufs to use */ ! 125: long sb_lowat; /* low water mark */ ! 126: struct mbuf *sb_mb; /* the mbuf chain */ ! 127: struct socket *sb_so; /* socket back ptr */ ! 128: struct selinfo sb_sel; /* process selecting read/write */ ! 129: short sb_flags; /* flags, see below */ ! 130: short sb_timeo; /* timeout for read/write */ ! 131: } so_rcv, so_snd; ! 132: #define SB_MAX (256*1024) /* default for max chars in sockbuf */ ! 133: #define SB_LOCK 0x01 /* lock on data queue */ ! 134: #define SB_WANT 0x02 /* someone is waiting to lock */ ! 135: #define SB_WAIT 0x04 /* someone is waiting for data/space */ ! 136: #define SB_SEL 0x08 /* someone is selecting */ ! 137: #define SB_ASYNC 0x10 /* ASYNC I/O, need signals */ ! 138: #define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC) ! 139: #define SB_NOINTR 0x40 /* operations not interruptible */ ! 140: #define SB_RECV 0x8000 /* this is rcv sb */ ! 141: ! 142: caddr_t so_tpcb; /* Wisc. protocol control block XXX */ ! 143: void (*so_upcall) __P((struct socket *so, caddr_t arg, int waitf)); ! 144: caddr_t so_upcallarg; /* Arg for above */ ! 145: int cached_in_sock_layer; /* Is socket bundled with pcb/pcb.inp_ppcb? */ ! 146: struct socket *cache_next; ! 147: struct socket *cache_prev; ! 148: u_long cache_timestamp; ! 149: caddr_t so_saved_pcb; /* Saved pcb when cacheing */ ! 150: TAILQ_HEAD(,eventqelt) so_evlist; ! 151: }; ! 152: ! 153: /* ! 154: * Socket state bits. ! 155: */ ! 156: #define SS_NOFDREF 0x001 /* no file table ref any more */ ! 157: #define SS_ISCONNECTED 0x002 /* socket connected to a peer */ ! 158: #define SS_ISCONNECTING 0x004 /* in process of connecting to peer */ ! 159: #define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */ ! 160: #define SS_CANTSENDMORE 0x010 /* can't send more data to peer */ ! 161: #define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */ ! 162: #define SS_RCVATMARK 0x040 /* at mark on input */ ! 163: ! 164: #define SS_PRIV 0x080 /* privileged for broadcast, raw... */ ! 165: #define SS_NBIO 0x100 /* non-blocking ops */ ! 166: #define SS_ASYNC 0x200 /* async i/o notify */ ! 167: #define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */ ! 168: #define SS_MORETOCOME 0x800 /* More data in the socket layer */ ! 169: ! 170: ! 171: /* ! 172: * Macros for sockets and socket buffering. ! 173: */ ! 174: ! 175: /* ! 176: * How much space is there in a socket buffer (so->so_snd or so->so_rcv)? ! 177: * This is problematical if the fields are unsigned, as the space might ! 178: * still be negative (cc > hiwat or mbcnt > mbmax). Should detect ! 179: * overflow and return 0. Should use "lmin" but it doesn't exist now. ! 180: */ ! 181: #define sbspace(sb) \ ! 182: ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \ ! 183: (int)((sb)->sb_mbmax - (sb)->sb_mbcnt))) ! 184: ! 185: /* do we have to send all at once on a socket? */ ! 186: #define sosendallatonce(so) \ ! 187: ((so)->so_proto->pr_flags & PR_ATOMIC) ! 188: ! 189: /* can we read something from so? */ ! 190: #define soreadable(so) \ ! 191: ((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \ ! 192: ((so)->so_state & SS_CANTRCVMORE) || \ ! 193: (so)->so_qlen || (so)->so_error) ! 194: ! 195: /* can we write something to so? */ ! 196: #define sowriteable(so) \ ! 197: (sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \ ! 198: (((so)->so_state&SS_ISCONNECTED) || \ ! 199: ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \ ! 200: ((so)->so_state & SS_CANTSENDMORE) || \ ! 201: (so)->so_error) ! 202: ! 203: /* adjust counters in sb reflecting allocation of m */ ! 204: #define sballoc(sb, m) { \ ! 205: (sb)->sb_cc += (m)->m_len; \ ! 206: (sb)->sb_mbcnt += MSIZE; \ ! 207: if ((m)->m_flags & M_EXT) \ ! 208: (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ ! 209: } ! 210: ! 211: /* adjust counters in sb reflecting freeing of m */ ! 212: #define sbfree(sb, m) { \ ! 213: (sb)->sb_cc -= (m)->m_len; \ ! 214: (sb)->sb_mbcnt -= MSIZE; \ ! 215: if ((m)->m_flags & M_EXT) \ ! 216: (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ ! 217: } ! 218: ! 219: /* ! 220: * Set lock on sockbuf sb; sleep if lock is already held. ! 221: * Unless SB_NOINTR is set on sockbuf, sleep is interruptible. ! 222: * Returns error without lock if sleep is interrupted. ! 223: */ ! 224: #define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \ ! 225: (((wf) == M_WAIT) ? sb_lock(sb) : EWOULDBLOCK) : \ ! 226: ((sb)->sb_flags |= SB_LOCK), 0) ! 227: ! 228: /* release lock on sockbuf sb */ ! 229: #define sbunlock(sb) { \ ! 230: (sb)->sb_flags &= ~SB_LOCK; \ ! 231: if ((sb)->sb_flags & SB_WANT) { \ ! 232: (sb)->sb_flags &= ~SB_WANT; \ ! 233: wakeup((caddr_t)&(sb)->sb_flags); \ ! 234: } \ ! 235: } ! 236: ! 237: #define sorwakeup(so) { sowakeup((so), &(so)->so_rcv); \ ! 238: if ((so)->so_upcall) \ ! 239: (*((so)->so_upcall))((so), (so)->so_upcallarg, M_DONTWAIT); \ ! 240: } ! 241: ! 242: #define sowwakeup(so) sowakeup((so), &(so)->so_snd) ! 243: ! 244: #ifdef _KERNEL ! 245: extern u_long sb_max; ! 246: /* to catch callers missing new second argument to sonewconn: */ ! 247: #define sonewconn(head, connstatus) sonewconn1((head), (connstatus)) ! 248: struct socket *sonewconn1 __P((struct socket *head, int connstatus)); ! 249: int getsock __P((struct proc *p, int fd, struct file **fpp)); ! 250: ! 251: /* strings for sleep message: */ ! 252: extern char netio[], netcon[], netcls[]; ! 253: ! 254: /* ! 255: * File operations on sockets. ! 256: */ ! 257: int soo_read __P((struct file *fp, struct uio *uio, struct ucred *cred)); ! 258: int soo_write __P((struct file *fp, struct uio *uio, struct ucred *cred)); ! 259: int soo_ioctl __P((struct file *fp, u_long cmd, caddr_t data, ! 260: struct proc *p)); ! 261: int soo_select __P((struct file *fp, int which, struct proc *p)); ! 262: int soo_close __P((struct file *fp, struct proc *p)); ! 263: ! 264: struct mbuf; ! 265: struct sockaddr; ! 266: ! 267: void sbappend __P((struct sockbuf *sb, struct mbuf *m)); ! 268: int sbappendaddr __P((struct sockbuf *sb, struct sockaddr *asa, ! 269: struct mbuf *m0, struct mbuf *control)); ! 270: int sbappendcontrol __P((struct sockbuf *sb, struct mbuf *m0, ! 271: struct mbuf *control)); ! 272: void sbappendrecord __P((struct sockbuf *sb, struct mbuf *m0)); ! 273: void sbcheck __P((struct sockbuf *sb)); ! 274: void sbcompress __P((struct sockbuf *sb, struct mbuf *m, struct mbuf *n)); ! 275: void sbdrop __P((struct sockbuf *sb, int len)); ! 276: void sbdroprecord __P((struct sockbuf *sb)); ! 277: void sbflush __P((struct sockbuf *sb)); ! 278: void sbinsertoob __P((struct sockbuf *sb, struct mbuf *m0)); ! 279: void sbrelease __P((struct sockbuf *sb)); ! 280: int sbreserve __P((struct sockbuf *sb, u_long cc)); ! 281: int sbwait __P((struct sockbuf *sb)); ! 282: int sb_lock __P((struct sockbuf *sb)); ! 283: int soabort __P((struct socket *so)); ! 284: int soaccept __P((struct socket *so, struct mbuf *nam)); ! 285: int sobind __P((struct socket *so, struct mbuf *nam)); ! 286: void socantrcvmore __P((struct socket *so)); ! 287: void socantsendmore __P((struct socket *so)); ! 288: int soclose __P((struct socket *so)); ! 289: int soconnect __P((struct socket *so, struct mbuf *nam)); ! 290: int soconnect2 __P((struct socket *so1, struct socket *so2)); ! 291: int socreate __P((int dom, struct socket **aso, int type, int proto)); ! 292: int sodisconnect __P((struct socket *so)); ! 293: int sofree __P((struct socket *so)); ! 294: int sogetopt __P((struct socket *so, int level, int optname, ! 295: struct mbuf **mp)); ! 296: void sohasoutofband __P((struct socket *so)); ! 297: void soisconnected __P((struct socket *so)); ! 298: void soisconnecting __P((struct socket *so)); ! 299: void soisdisconnected __P((struct socket *so)); ! 300: void soisdisconnecting __P((struct socket *so)); ! 301: int solisten __P((struct socket *so, int backlog)); ! 302: struct socket * ! 303: sonewconn1 __P((struct socket *head, int connstatus)); ! 304: void soqinsque __P((struct socket *head, struct socket *so, int q)); ! 305: int soqremque __P((struct socket *so, int q)); ! 306: int soreceive __P((struct socket *so, struct mbuf **paddr, struct uio *uio, ! 307: struct mbuf **mp0, struct mbuf **controlp, int *flagsp)); ! 308: int soreserve __P((struct socket *so, u_long sndcc, u_long rcvcc)); ! 309: void sorflush __P((struct socket *so)); ! 310: int sosend __P((struct socket *so, struct mbuf *addr, struct uio *uio, ! 311: struct mbuf *top, struct mbuf *control, int flags)); ! 312: int sosetopt __P((struct socket *so, int level, int optname, ! 313: struct mbuf *m0)); ! 314: int soshutdown __P((struct socket *so, int how)); ! 315: void sowakeup __P((struct socket *so, struct sockbuf *sb)); ! 316: #endif /* _KERNEL */ ! 317: #endif /* !_SYS_SOCKETVAR_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.