Annotation of 43BSDTahoe/sys/h/socketvar.h, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1982, 1986 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  *
        !            17:  *     @(#)socketvar.h 7.4 (Berkeley) 6/27/88
        !            18:  */
        !            19: 
        !            20: /*
        !            21:  * Kernel structure per socket.
        !            22:  * Contains send and receive buffer queues,
        !            23:  * handle on protocol and pointer to protocol
        !            24:  * private data and error information.
        !            25:  */
        !            26: struct socket {
        !            27:        short   so_type;                /* generic type, see socket.h */
        !            28:        short   so_options;             /* from socket call, see socket.h */
        !            29:        short   so_linger;              /* time to linger while closing */
        !            30:        short   so_state;               /* internal state flags SS_*, below */
        !            31:        caddr_t so_pcb;                 /* protocol control block */
        !            32:        struct  protosw *so_proto;      /* protocol handle */
        !            33: /*
        !            34:  * Variables for connection queueing.
        !            35:  * Socket where accepts occur is so_head in all subsidiary sockets.
        !            36:  * If so_head is 0, socket is not related to an accept.
        !            37:  * For head socket so_q0 queues partially completed connections,
        !            38:  * while so_q is a queue of connections ready to be accepted.
        !            39:  * If a connection is aborted and it has so_head set, then
        !            40:  * it has to be pulled out of either so_q0 or so_q.
        !            41:  * We allow connections to queue up based on current queue lengths
        !            42:  * and limit on number of queued connections for this socket.
        !            43:  */
        !            44:        struct  socket *so_head;        /* back pointer to accept socket */
        !            45:        struct  socket *so_q0;          /* queue of partial connections */
        !            46:        struct  socket *so_q;           /* queue of incoming connections */
        !            47:        short   so_q0len;               /* partials on so_q0 */
        !            48:        short   so_qlen;                /* number of connections on so_q */
        !            49:        short   so_qlimit;              /* max number queued connections */
        !            50:        short   so_timeo;               /* connection timeout */
        !            51:        u_short so_error;               /* error affecting connection */
        !            52:        short   so_pgrp;                /* pgrp for signals */
        !            53:        u_long  so_oobmark;             /* chars to oob mark */
        !            54: /*
        !            55:  * Variables for socket buffering.
        !            56:  */
        !            57:        struct  sockbuf {
        !            58:                u_long  sb_cc;          /* actual chars in buffer */
        !            59:                u_long  sb_hiwat;       /* max actual char count */
        !            60:                u_long  sb_mbcnt;       /* chars of mbufs used */
        !            61:                u_long  sb_mbmax;       /* max chars of mbufs to use */
        !            62:                u_long  sb_lowat;       /* low water mark (not used yet) */
        !            63:                struct  mbuf *sb_mb;    /* the mbuf chain */
        !            64:                struct  proc *sb_sel;   /* process selecting read/write */
        !            65:                short   sb_timeo;       /* timeout (not used yet) */
        !            66:                short   sb_flags;       /* flags, see below */
        !            67:        } so_rcv, so_snd;
        !            68: #define        SB_MAX          (64*1024)       /* max chars in sockbuf */
        !            69: #define        SB_LOCK         0x01            /* lock on data queue (so_rcv only) */
        !            70: #define        SB_WANT         0x02            /* someone is waiting to lock */
        !            71: #define        SB_WAIT         0x04            /* someone is waiting for data/space */
        !            72: #define        SB_SEL          0x08            /* buffer is selected */
        !            73: #define        SB_COLL         0x10            /* collision selecting */
        !            74: };
        !            75: 
        !            76: /*
        !            77:  * Socket state bits.
        !            78:  */
        !            79: #define        SS_NOFDREF              0x001   /* no file table ref any more */
        !            80: #define        SS_ISCONNECTED          0x002   /* socket connected to a peer */
        !            81: #define        SS_ISCONNECTING         0x004   /* in process of connecting to peer */
        !            82: #define        SS_ISDISCONNECTING      0x008   /* in process of disconnecting */
        !            83: #define        SS_CANTSENDMORE         0x010   /* can't send more data to peer */
        !            84: #define        SS_CANTRCVMORE          0x020   /* can't receive more data from peer */
        !            85: #define        SS_RCVATMARK            0x040   /* at mark on input */
        !            86: 
        !            87: #define        SS_PRIV                 0x080   /* privileged for broadcast, raw... */
        !            88: #define        SS_NBIO                 0x100   /* non-blocking ops */
        !            89: #define        SS_ASYNC                0x200   /* async i/o notify */
        !            90: 
        !            91: 
        !            92: /*
        !            93:  * Macros for sockets and socket buffering.
        !            94:  */
        !            95: 
        !            96: /* how much space is there in a socket buffer (so->so_snd or so->so_rcv) */
        !            97: #define        sbspace(sb) \
        !            98:     (MIN((long)((sb)->sb_hiwat - (sb)->sb_cc),\
        !            99:         (long)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
        !           100: 
        !           101: /* do we have to send all at once on a socket? */
        !           102: #define        sosendallatonce(so) \
        !           103:     ((so)->so_proto->pr_flags & PR_ATOMIC)
        !           104: 
        !           105: /* can we read something from so? */
        !           106: #define        soreadable(so) \
        !           107:     ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || \
        !           108:        (so)->so_qlen || (so)->so_error)
        !           109: 
        !           110: /* can we write something to so? */
        !           111: #define        sowriteable(so) \
        !           112:     (sbspace(&(so)->so_snd) > 0 && \
        !           113:        (((so)->so_state&SS_ISCONNECTED) || \
        !           114:          ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \
        !           115:      ((so)->so_state & SS_CANTSENDMORE) || \
        !           116:      (so)->so_error)
        !           117: 
        !           118: /* adjust counters in sb reflecting allocation of m */
        !           119: #define        sballoc(sb, m) { \
        !           120:        (sb)->sb_cc += (m)->m_len; \
        !           121:        (sb)->sb_mbcnt += MSIZE; \
        !           122:        if ((m)->m_off > MMAXOFF) \
        !           123:                (sb)->sb_mbcnt += CLBYTES; \
        !           124: }
        !           125: 
        !           126: /* adjust counters in sb reflecting freeing of m */
        !           127: #define        sbfree(sb, m) { \
        !           128:        (sb)->sb_cc -= (m)->m_len; \
        !           129:        (sb)->sb_mbcnt -= MSIZE; \
        !           130:        if ((m)->m_off > MMAXOFF) \
        !           131:                (sb)->sb_mbcnt -= CLBYTES; \
        !           132: }
        !           133: 
        !           134: /* set lock on sockbuf sb */
        !           135: #define sblock(sb) { \
        !           136:        while ((sb)->sb_flags & SB_LOCK) { \
        !           137:                (sb)->sb_flags |= SB_WANT; \
        !           138:                sleep((caddr_t)&(sb)->sb_flags, PZERO+1); \
        !           139:        } \
        !           140:        (sb)->sb_flags |= SB_LOCK; \
        !           141: }
        !           142: 
        !           143: /* release lock on sockbuf sb */
        !           144: #define        sbunlock(sb) { \
        !           145:        (sb)->sb_flags &= ~SB_LOCK; \
        !           146:        if ((sb)->sb_flags & SB_WANT) { \
        !           147:                (sb)->sb_flags &= ~SB_WANT; \
        !           148:                wakeup((caddr_t)&(sb)->sb_flags); \
        !           149:        } \
        !           150: }
        !           151: 
        !           152: #define        sorwakeup(so)   sowakeup((so), &(so)->so_rcv)
        !           153: #define        sowwakeup(so)   sowakeup((so), &(so)->so_snd)
        !           154: 
        !           155: #ifdef KERNEL
        !           156: struct socket *sonewconn();
        !           157: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.