home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / x11r6.1 / include / x11 / xpoll.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  6.0 KB  |  192 lines

  1. /* $XConsortium: Xpoll.h,v 1.2 95/04/05 19:57:45 kaleb Exp $ */
  2.  
  3. /*
  4.  
  5. Copyright (c) 1994  X Consortium
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining
  8. a copy of this software and associated documentation files (the
  9. "Software"), to deal in the Software without restriction, including
  10. without limitation the rights to use, copy, modify, merge, publish,
  11. distribute, sublicense, and/or sell copies of the Software, and to
  12. permit persons to whom the Software is furnished to do so, subject to
  13. the following conditions:
  14.  
  15. The above copyright notice and this permission notice shall be included
  16. in all copies or substantial portions of the Software.
  17.  
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. OTHER DEALINGS IN THE SOFTWARE.
  25.  
  26. Except as contained in this notice, the name of the X Consortium shall
  27. not be used in advertising or otherwise to promote the sale, use or
  28. other dealings in this Software without prior written authorization
  29. from the X Consortium.
  30.  
  31. */
  32.  
  33. #ifndef _XPOLL_H_
  34. #define _XPOLL_H_
  35.  
  36. #ifndef WIN32
  37.  
  38. #ifndef USE_POLL
  39.  
  40. #include <X11/Xos.h>
  41. #if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
  42. #include <sys/select.h>
  43. #ifdef luna
  44. #include <sysent.h>
  45. #endif
  46. #endif
  47. #include <X11/Xmd.h>
  48. #ifdef CSRG_BASED
  49. #include <sys/param.h>
  50. #ifdef BSD
  51. # if BSD < 199103
  52. typedef long fd_mask;
  53. # endif
  54. #endif
  55. #endif
  56.  
  57. #define XFD_SETSIZE    256
  58. #ifndef FD_SETSIZE
  59. #define FD_SETSIZE    XFD_SETSIZE
  60. #endif
  61.  
  62. #ifndef NBBY
  63. #define NBBY    8        /* number of bits in a byte */
  64. #endif
  65.  
  66. #ifndef NFDBITS
  67. #define NFDBITS (sizeof(fd_mask) * NBBY)    /* bits per mask */
  68. #endif
  69.  
  70. #ifndef howmany
  71. #define howmany(x,y)    (((x)+((y)-1))/(y))
  72. #endif
  73.  
  74. #ifdef BSD
  75. # if BSD < 198911    /* 198911 == OSF/1, 199103 == CSRG_BASED */
  76. #  ifndef luna        /* and even though on LUNA BSD ==  43, it has it */
  77. typedef struct fd_set {
  78.     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
  79. } fd_set;
  80. #  endif
  81. # endif
  82. #endif
  83.  
  84. #ifdef hpux /* and perhaps old BSD ??? */
  85. #define Select(n,r,w,e,t) select(n,(int*)r,(int*)w,(int*)e,(struct timeval*)t)
  86. #else
  87. #define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
  88. #endif
  89.  
  90. #ifndef FD_SET
  91. #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  92. #endif
  93. #ifndef FD_CLR
  94. #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  95. #endif
  96. #ifndef FD_ISSET
  97. #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  98. #endif
  99. #ifndef FD_ZERO
  100. #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
  101. #endif
  102.  
  103. /*
  104.  * The following macros are used by the servers only. There is an
  105.  * explicit assumption that the bit array in the fd_set is at least
  106.  * 256 bits long (8 32-bit words). This is true on most modern POSIX 
  107.  * systems. Note that this is merely an optimization for the servers
  108.  * based on assumptions about the way that file descripters are
  109.  * allocated on POSIX systems. 
  110.  *
  111.  * When porting X to new systems it is important to adjust these
  112.  * macros if the system has fewer than 256 bits in the fd_set bit
  113.  * array.
  114.  */
  115. #define XFD_ANYSET(p) \
  116.         ((p)->fds_bits[0] || (p)->fds_bits[1] || \
  117.         (p)->fds_bits[2] || (p)->fds_bits[3] || \
  118.         (p)->fds_bits[4] || (p)->fds_bits[5] || \
  119.         (p)->fds_bits[6] || (p)->fds_bits[7])
  120.  
  121. #define XFD_COPYSET(src,dst) \
  122.         (dst)->fds_bits[0] = (src)->fds_bits[0]; \
  123.         (dst)->fds_bits[1] = (src)->fds_bits[1]; \
  124.         (dst)->fds_bits[2] = (src)->fds_bits[2]; \
  125.         (dst)->fds_bits[3] = (src)->fds_bits[3]; \
  126.         (dst)->fds_bits[4] = (src)->fds_bits[4]; \
  127.         (dst)->fds_bits[5] = (src)->fds_bits[5]; \
  128.         (dst)->fds_bits[6] = (src)->fds_bits[6]; \
  129.         (dst)->fds_bits[7] = (src)->fds_bits[7];
  130.  
  131. #define XFD_ANDSET(dst,b1,b2) \
  132.         (dst)->fds_bits[0] = ((b1)->fds_bits[0] & (b2)->fds_bits[0]); \
  133.         (dst)->fds_bits[1] = ((b1)->fds_bits[1] & (b2)->fds_bits[1]); \
  134.         (dst)->fds_bits[2] = ((b1)->fds_bits[2] & (b2)->fds_bits[2]); \
  135.         (dst)->fds_bits[3] = ((b1)->fds_bits[3] & (b2)->fds_bits[3]); \
  136.         (dst)->fds_bits[4] = ((b1)->fds_bits[4] & (b2)->fds_bits[4]); \
  137.         (dst)->fds_bits[5] = ((b1)->fds_bits[5] & (b2)->fds_bits[5]); \
  138.         (dst)->fds_bits[6] = ((b1)->fds_bits[6] & (b2)->fds_bits[6]); \
  139.         (dst)->fds_bits[7] = ((b1)->fds_bits[7] & (b2)->fds_bits[7]);
  140.  
  141. #define XFD_ORSET(dst,b1,b2) \
  142.         (dst)->fds_bits[0] = ((b1)->fds_bits[0] | (b2)->fds_bits[0]); \
  143.         (dst)->fds_bits[1] = ((b1)->fds_bits[1] | (b2)->fds_bits[1]); \
  144.         (dst)->fds_bits[2] = ((b1)->fds_bits[2] | (b2)->fds_bits[2]); \
  145.         (dst)->fds_bits[3] = ((b1)->fds_bits[3] | (b2)->fds_bits[3]); \
  146.         (dst)->fds_bits[4] = ((b1)->fds_bits[4] | (b2)->fds_bits[4]); \
  147.         (dst)->fds_bits[5] = ((b1)->fds_bits[5] | (b2)->fds_bits[5]); \
  148.         (dst)->fds_bits[6] = ((b1)->fds_bits[6] | (b2)->fds_bits[6]); \
  149.         (dst)->fds_bits[7] = ((b1)->fds_bits[7] | (b2)->fds_bits[7]);
  150.  
  151. #define XFD_UNSET(dst,b1) \
  152.         (dst)->fds_bits[0] &= ~((b1)->fds_bits[0]); \
  153.         (dst)->fds_bits[1] &= ~((b1)->fds_bits[1]); \
  154.         (dst)->fds_bits[2] &= ~((b1)->fds_bits[2]); \
  155.         (dst)->fds_bits[3] &= ~((b1)->fds_bits[3]); \
  156.         (dst)->fds_bits[4] &= ~((b1)->fds_bits[4]); \
  157.         (dst)->fds_bits[5] &= ~((b1)->fds_bits[5]); \
  158.         (dst)->fds_bits[6] &= ~((b1)->fds_bits[6]); \
  159.         (dst)->fds_bits[7] &= ~((b1)->fds_bits[7]);
  160.  
  161. #else /* USE_POLL */
  162. #include <sys/poll.h>
  163. #endif /* USE_POLL */
  164.  
  165. #else /* WIN32 */
  166.  
  167. #ifndef FD_SETSIZE
  168. #define FD_SETSIZE      256
  169. #endif
  170. #define BOOL wBOOL
  171. #undef Status
  172. #define Status wStatus
  173. #include <winsock.h>
  174. #undef Status
  175. #define Status int
  176. #undef BOOL
  177. #define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
  178.  
  179. /* 
  180.  * These are merely placeholders for the present, to allow servers to
  181.  * be compiled on WinNT. Eventually they need to be filled in.
  182.  */
  183. #define XFD_ANYSET(p)    1
  184. #define XFD_COPYSET(src,dst)
  185. #define XFD_ANDSET(dst,b1,b2)
  186. #define XFD_ORSET(dst,b1,b2)
  187. #define XFD_UNSET(dst,b1)
  188.  
  189. #endif /* WIN32 */
  190.  
  191. #endif /* _XPOLL_H_ */
  192.