home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / os / osdep.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-23  |  6.1 KB  |  192 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: osdep.h,v 1.27 91/07/23 19:04:22 rws Exp $ */
  25.  
  26. #define BOTIMEOUT 200 /* in milliseconds */
  27. #define BUFSIZE 4096
  28. #define BUFWATERMARK 8192
  29. #define MAXBUFSIZE (1 << 18)
  30.  
  31. #ifndef X_NOT_POSIX
  32. #ifdef _POSIX_SOURCE
  33. #include <limits.h>
  34. #else
  35. #define _POSIX_SOURCE
  36. #include <limits.h>
  37. #undef _POSIX_SOURCE
  38. #endif
  39. #endif
  40. #ifndef OPEN_MAX
  41. #ifdef SVR4
  42. #define OPEN_MAX 128
  43. #else
  44. #include <sys/param.h>
  45. #ifndef OPEN_MAX
  46. #ifdef NOFILE
  47. #define OPEN_MAX NOFILE
  48. #else
  49. #define OPEN_MAX NOFILES_MAX
  50. #endif
  51. #endif
  52. #endif
  53. #endif
  54.  
  55. #if OPEN_MAX <= 128
  56. #define MAXSOCKS (OPEN_MAX - 1)
  57. #else
  58. #define MAXSOCKS 128
  59. #endif
  60.  
  61. #ifndef NULL
  62. #define NULL 0
  63. #endif
  64.  
  65. #define mskcnt ((MAXSOCKS + 31) / 32)    /* size of bit array */
  66.  
  67. #if (mskcnt==1)
  68. #define BITMASK(i) (1 << (i))
  69. #define MASKIDX(i) 0
  70. #endif
  71. #if (mskcnt>1)
  72. #define BITMASK(i) (1 << ((i) & 31))
  73. #define MASKIDX(i) ((i) >> 5)
  74. #endif
  75.  
  76. #define MASKWORD(buf, i) buf[MASKIDX(i)]
  77. #define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
  78. #define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
  79. #define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
  80.  
  81. #if (mskcnt==1)
  82. #define COPYBITS(src, dst) dst[0] = src[0]
  83. #define CLEARBITS(buf) buf[0] = 0
  84. #define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
  85. #define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
  86. #define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
  87. #define ANYSET(src) (src[0])
  88. #endif
  89. #if (mskcnt==2)
  90. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]
  91. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0
  92. #define MASKANDSETBITS(dst, b1, b2)  \
  93.               dst[0] = (b1[0] & b2[0]);\
  94.               dst[1] = (b1[1] & b2[1])
  95. #define ORBITS(dst, b1, b2)  \
  96.               dst[0] = (b1[0] | b2[0]);\
  97.               dst[1] = (b1[1] | b2[1])
  98. #define UNSETBITS(dst, b1) \
  99.                       dst[0] &= ~b1[0]; \
  100.                       dst[1] &= ~b1[1]
  101. #define ANYSET(src) (src[0] || src[1])
  102. #endif
  103. #if (mskcnt==3)
  104. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2];
  105. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0
  106. #define MASKANDSETBITS(dst, b1, b2)  \
  107.               dst[0] = (b1[0] & b2[0]);\
  108.               dst[1] = (b1[1] & b2[1]);\
  109.               dst[2] = (b1[2] & b2[2])
  110. #define ORBITS(dst, b1, b2)  \
  111.               dst[0] = (b1[0] | b2[0]);\
  112.               dst[1] = (b1[1] | b2[1]);\
  113.               dst[2] = (b1[2] | b2[2])
  114. #define UNSETBITS(dst, b1) \
  115.                       dst[0] &= ~b1[0]; \
  116.                       dst[1] &= ~b1[1]; \
  117.                       dst[2] &= ~b1[2]
  118. #define ANYSET(src) (src[0] || src[1] || src[2])
  119. #endif
  120. #if (mskcnt==4)
  121. #define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2];\
  122.               dst[3] = src[3]
  123. #define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
  124. #define MASKANDSETBITS(dst, b1, b2)  \
  125.                       dst[0] = (b1[0] & b2[0]);\
  126.                       dst[1] = (b1[1] & b2[1]);\
  127.                       dst[2] = (b1[2] & b2[2]);\
  128.                       dst[3] = (b1[3] & b2[3])
  129. #define ORBITS(dst, b1, b2)  \
  130.                       dst[0] = (b1[0] | b2[0]);\
  131.                       dst[1] = (b1[1] | b2[1]);\
  132.                       dst[2] = (b1[2] | b2[2]);\
  133.                       dst[3] = (b1[3] | b2[3])
  134. #define UNSETBITS(dst, b1) \
  135.                       dst[0] &= ~b1[0]; \
  136.                       dst[1] &= ~b1[1]; \
  137.                       dst[2] &= ~b1[2]; \
  138.                       dst[3] &= ~b1[3]
  139. #define ANYSET(src) (src[0] || src[1] || src[2] || src[3])
  140. #endif
  141.  
  142. #if (mskcnt>4)
  143. #define COPYBITS(src, dst) bcopy((caddr_t) src, (caddr_t) dst,\
  144.                  mskcnt*sizeof(long))
  145. #define CLEARBITS(buf) bzero((caddr_t) buf, mskcnt*sizeof(long))
  146. #define MASKANDSETBITS(dst, b1, b2)  \
  147.               { int cri;            \
  148.             for (cri=mskcnt; --cri>=0; )    \
  149.                   dst[cri] = (b1[cri] & b2[cri]); }
  150. #define ORBITS(dst, b1, b2)  \
  151.               { int cri;            \
  152.               for (cri=mskcnt; --cri>=0; )    \
  153.                   dst[cri] = (b1[cri] | b2[cri]); }
  154. #define UNSETBITS(dst, b1) \
  155.               { int cri;            \
  156.               for (cri=mskcnt; --cri>=0; )    \
  157.                   dst[cri] &= ~b1[cri];  }
  158. #if (mskcnt==8)
  159. #define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || \
  160.              src[4] || src[5] || src[6] || src[7])
  161. #endif
  162. /*
  163.  * If mskcnt>4 and not 8, then ANYSET is a routine defined in WaitFor.c.
  164.  *
  165.  * #define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
  166.  */
  167. #endif
  168.  
  169. typedef struct _connectionInput {
  170.     struct _connectionInput *next;
  171.     char *buffer;               /* contains current client input */
  172.     char *bufptr;               /* pointer to current start of data */
  173.     int  bufcnt;                /* count of bytes in buffer */
  174.     int lenLastReq;
  175.     int size;
  176. } ConnectionInput, *ConnectionInputPtr;
  177.  
  178. typedef struct _connectionOutput {
  179.     struct _connectionOutput *next;
  180.     int size;
  181.     unsigned char *buf;
  182.     int count;
  183. } ConnectionOutput, *ConnectionOutputPtr;
  184.  
  185. typedef struct _osComm {
  186.     int fd;
  187.     ConnectionInputPtr input;
  188.     ConnectionOutputPtr output;
  189.     XID    auth_id;        /* authorization id */
  190.     long conn_time;        /* timestamp if not established, else 0  */
  191. } OsCommRec, *OsCommPtr;
  192.