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

Defined struct's

sockbuf defined in line 52; used 40 times
socket defined in line 21; used 280 times

Defined macros

SB_COLL defined in line 72; used 5 times
SB_LOCK defined in line 68; used 5 times
SB_MAX defined in line 66; used 3 times
SB_SEL defined in line 71; never used
SB_WANT defined in line 69; used 3 times
SS_ASYNC defined in line 88; used 3 times
SS_ISCONNECTING defined in line 80; used 10 times
SS_NBIO defined in line 87; used 9 times
SS_PRIV defined in line 86; used 2 times
sballoc defined in line 118; used 5 times
sbfree defined in line 126; used 6 times
sblock defined in line 134; used 3 times
sbunlock defined in line 143; used 5 times
soreadable defined in line 105; used 1 times
sosendallatonce defined in line 101; used 2 times
sowriteable defined in line 110; used 1 times

Usage of this include

socketvar.h used 43 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 175
Valid CSS Valid XHTML 1.0 Strict