home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilss / sockets / include / sys / h / socketvar < prev    next >
Encoding:
Text File  |  1995-01-12  |  6.7 KB  |  179 lines

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