home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 8.ddi / usr / include / sys / socketvar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  6.6 KB  |  199 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_SOCKETVAR_H
  11. #define _SYS_SOCKETVAR_H
  12.  
  13. #ident    "@(#)/usr/include/sys/socketvar.h.sl 1.1 4.0 12/08/90 38916 AT&T-USL"
  14.  
  15. /*
  16.  *          PROPRIETARY NOTICE (Combined)
  17.  *  
  18.  *  This source code is unpublished proprietary information
  19.  *  constituting, or derived under license from AT&T's Unix(r) System V.
  20.  *  In addition, portions of such source code were derived from Berkeley
  21.  *  4.3 BSD under license from the Regents of the University of
  22.  *  California.
  23.  *  
  24.  *  
  25.  *  
  26.  *          Copyright Notice 
  27.  *  
  28.  *  Notice of copyright on this source code product does not indicate 
  29.  *  publication.
  30.  *  
  31.  *      (c) 1986,1987,1988,1989  Sun Microsystems, Inc.
  32.  *      (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
  33.  *                All rights reserved.
  34.  */
  35.  
  36. /*
  37.  * Kernel structure per socket.
  38.  * Contains send and receive buffer queues,
  39.  * handle on protocol and pointer to protocol
  40.  * private data and error information.
  41.  */
  42. struct socket {
  43.     short    so_type;        /* generic type, see socket.h */
  44.     short    so_options;        /* from socket call, see socket.h */
  45.     short    so_linger;        /* time to linger while closing */
  46.     short    so_state;        /* internal state flags SS_*, below */
  47.     caddr_t    so_pcb;            /* protocol control block */
  48.     struct    protosw *so_proto;    /* protocol handle */
  49. /*
  50.  * Variables for connection queueing.
  51.  * Socket where accepts occur is so_head in all subsidiary sockets.
  52.  * If so_head is 0, socket is not related to an accept.
  53.  * For head socket so_q0 queues partially completed connections,
  54.  * while so_q is a queue of connections ready to be accepted.
  55.  * If a connection is aborted and it has so_head set, then
  56.  * it has to be pulled out of either so_q0 or so_q.
  57.  * We allow connections to queue up based on current queue lengths
  58.  * and limit on number of queued connections for this socket.
  59.  */
  60.     struct    socket *so_head;    /* back pointer to accept socket */
  61.     struct    socket *so_q0;        /* queue of partial connections */
  62.     struct    socket *so_q;        /* queue of incoming connections */
  63.     short    so_q0len;        /* partials on so_q0 */
  64.     short    so_qlen;        /* number of connections on so_q */
  65.     short    so_qlimit;        /* max number queued connections */
  66.     short    so_timeo;        /* connection timeout */
  67.     u_short    so_error;        /* error affecting connection */
  68.     short    so_pgrp;        /* pgrp for signals */
  69.     u_long    so_oobmark;        /* chars to oob mark */
  70. /*
  71.  * Variables for socket buffering.
  72.  */
  73.     struct    sockbuf {
  74.         u_long    sb_cc;        /* actual chars in buffer */
  75.         u_long    sb_hiwat;    /* max actual char count */
  76.         u_long    sb_mbcnt;    /* chars of mbufs used */
  77.         u_long    sb_mbmax;    /* max chars of mbufs to use */
  78.         u_long    sb_lowat;    /* low water mark (not used yet) */
  79.         struct    mbuf *sb_mb;    /* the mbuf chain */
  80.         struct    proc *sb_sel;    /* process selecting read/write */
  81.         short    sb_timeo;    /* timeout (not used yet) */
  82.         short    sb_flags;    /* flags, see below */
  83.     } so_rcv, so_snd;
  84. #define    SB_MAX        (64*1024)    /* max chars in sockbuf */
  85. #define    SB_LOCK        0x01        /* lock on data queue (so_rcv only) */
  86. #define    SB_WANT        0x02        /* someone is waiting to lock */
  87. #define    SB_WAIT        0x04        /* someone is waiting for data/space */
  88. #define    SB_SEL        0x08        /* buffer is selected */
  89. #define    SB_COLL        0x10        /* collision selecting */
  90. /*
  91.  * Hooks for alternative wakeup strategies.
  92.  * These are used by kernel subsystems wishing to access the socket
  93.  * abstraction.  If so_wupfunc is nonnull, it is called in place of
  94.  * wakeup any time that wakeup would otherwise be called with an
  95.  * argument whose value is an address lying within a socket structure.
  96.  */
  97.     struct wupalt    *so_wupalt;
  98. };
  99.  
  100. struct wupalt {
  101.     int    (*wup_func)();        /* function to call instead of wakeup */
  102.     caddr_t    wup_arg;        /* argument for so_wupfunc */
  103.     /*
  104.      * Other state information here, for example, for a stream
  105.      * connected to a socket.
  106.      */
  107. };
  108.  
  109. /*
  110.  * Socket state bits.
  111.  */
  112. #define    SS_NOFDREF        0x001    /* no file table ref any more */
  113. #define    SS_ISCONNECTED        0x002    /* socket connected to a peer */
  114. #define    SS_ISCONNECTING        0x004    /* in process of connecting to peer */
  115. #define    SS_ISDISCONNECTING    0x008    /* in process of disconnecting */
  116. #define    SS_CANTSENDMORE        0x010    /* can't send more data to peer */
  117. #define    SS_CANTRCVMORE        0x020    /* can't receive more data from peer */
  118. #define    SS_RCVATMARK        0x040    /* at mark on input */
  119. #define SS_ISBOUND        0x080    /* socket is bound */
  120.  
  121. #define    SS_PRIV            0x080    /* privileged for broadcast, raw... */
  122. #define    SS_NBIO            0x100    /* non-blocking ops */
  123. #define    SS_ASYNC        0x200    /* async i/o notify */
  124.  
  125.  
  126. /*
  127.  * Macros for sockets and socket buffering.
  128.  */
  129.  
  130. /* how much space is there in a socket buffer (so->so_snd or so->so_rcv) */
  131. #define    sbspace(sb) \
  132.     (MIN((int)((sb)->sb_hiwat - (sb)->sb_cc),\
  133.      (int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
  134.  
  135. /* do we have to send all at once on a socket? */
  136. #define    sosendallatonce(so) \
  137.     ((so)->so_proto->pr_flags & PR_ATOMIC)
  138.  
  139. /* can we read something from so? */
  140. #define    soreadable(so) \
  141.     ((so)->so_rcv.sb_cc || ((so)->so_state & SS_CANTRCVMORE) || \
  142.     (so)->so_qlen || (so)->so_error)
  143.  
  144. /* can we write something to so? */
  145. #define    sowriteable(so) \
  146.     (sbspace(&(so)->so_snd) > 0 && \
  147.     (((so)->so_state&SS_ISCONNECTED) || \
  148.       ((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0) || \
  149.      ((so)->so_state & SS_CANTSENDMORE) || \
  150.      (so)->so_error)
  151.  
  152. /* adjust counters in sb reflecting allocation of m */
  153. #define    sballoc(sb, m) { \
  154.     (sb)->sb_cc += (m)->m_len; \
  155.     (sb)->sb_mbcnt += MSIZE; \
  156.     if ((m)->m_off > MMAXOFF) \
  157.         (sb)->sb_mbcnt += MCLBYTES; \
  158. }
  159.  
  160. /* adjust counters in sb reflecting freeing of m */
  161. #define    sbfree(sb, m) { \
  162.     (sb)->sb_cc -= (m)->m_len; \
  163.     (sb)->sb_mbcnt -= MSIZE; \
  164.     if ((m)->m_off > MMAXOFF) \
  165.         (sb)->sb_mbcnt -= MCLBYTES; \
  166. }
  167.  
  168. /* set lock on sockbuf sb */
  169. #define    sblock(so, sb) { \
  170.     while ((sb)->sb_flags & SB_LOCK) { \
  171.         (sb)->sb_flags |= SB_WANT; \
  172.         (void) sleep((caddr_t)&(sb)->sb_flags, PZERO+1); \
  173.     } \
  174.     (sb)->sb_flags |= SB_LOCK; \
  175. }
  176.  
  177. /* release lock on sockbuf sb */
  178. #define    sbunlock(so, sb) { \
  179.     (sb)->sb_flags &= ~SB_LOCK; \
  180.     if ((sb)->sb_flags & SB_WANT) { \
  181.         (sb)->sb_flags &= ~SB_WANT; \
  182.         if ((so)->so_wupalt) \
  183.             (*(so)->so_wupalt->wup_func)(so, \
  184.             (caddr_t)&(sb)->sb_flags, \
  185.                 (so)->so_wupalt->wup_arg);\
  186.         else \
  187.             wakeup((caddr_t)&(sb)->sb_flags); \
  188.     } \
  189. }
  190.  
  191. #define    sorwakeup(so)    sowakeup((so), &(so)->so_rcv)
  192. #define    sowwakeup(so)    sowakeup((so), &(so)->so_snd)
  193.  
  194. #ifdef _KERNEL
  195. struct    socket *sonewconn();
  196. #endif
  197.  
  198. #endif    /* _SYS_SOCKETVAR_H */
  199.