File indexing completed on 2025-01-18 10:15:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef _XPOLL_H_
0029 #define _XPOLL_H_
0030
0031 #ifndef WIN32
0032
0033 #ifndef USE_POLL
0034
0035 #include <X11/Xos.h>
0036 #if !defined(DGUX)
0037 #if (defined(SVR4) || defined(CRAY) || defined(AIXV3)) && !defined(FD_SETSIZE)
0038 #include <sys/select.h>
0039 #ifdef luna
0040 #include <sysent.h>
0041 #endif
0042 #endif
0043 #else
0044 #include <sys/time.h>
0045 #include <sys/types.h>
0046 #include <unistd.h>
0047 #endif
0048
0049 #ifdef __QNX__
0050 #define FD_SETSIZE 256
0051 #include <sys/select.h>
0052 #endif
0053
0054
0055 #if defined(AIXV4) && !defined(NFDBITS)
0056 #include <sys/select.h>
0057 #endif
0058 #include <X11/Xmd.h>
0059 #ifdef CSRG_BASED
0060 #include <sys/param.h>
0061 # if BSD < 199103
0062 typedef long fd_mask;
0063 # endif
0064 #endif
0065
0066 #define XFD_SETSIZE 256
0067 #ifndef FD_SETSIZE
0068 #define FD_SETSIZE XFD_SETSIZE
0069 #endif
0070
0071 #ifndef NBBY
0072 #define NBBY 8
0073 #endif
0074
0075 #ifndef NFDBITS
0076 #define NFDBITS (sizeof(fd_mask) * NBBY)
0077 #endif
0078
0079 #ifndef howmany
0080 #define howmany(x,y) (((x)+((y)-1))/(y))
0081 #endif
0082
0083 #ifdef BSD
0084 # if BSD < 198911
0085 # ifndef luna
0086 typedef struct fd_set {
0087 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
0088 } fd_set;
0089 # endif
0090 # endif
0091 #endif
0092
0093 #ifndef hpux
0094 # define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
0095 #else
0096 # ifndef _XPG4_EXTENDED
0097 # define Select(n,r,w,e,t) select(n,(int*)r,(int*)w,(int*)e,(struct timeval*)t)
0098 # else
0099 # define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
0100 # endif
0101 #endif
0102
0103 #ifndef FD_SET
0104 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= ((fd_mask)1 << ((n) % NFDBITS)))
0105 #endif
0106 #ifndef FD_CLR
0107 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~((fd_mask)1 << ((n) % NFDBITS)))
0108 #endif
0109 #ifndef FD_ISSET
0110 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & ((fd_mask)1 << ((n) % NFDBITS)))
0111 #endif
0112 #ifndef FD_ZERO
0113 #define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
0114 #endif
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 #define XFD_ANYSET(p) \
0129 ((p)->fds_bits[0] || (p)->fds_bits[1] || \
0130 (p)->fds_bits[2] || (p)->fds_bits[3] || \
0131 (p)->fds_bits[4] || (p)->fds_bits[5] || \
0132 (p)->fds_bits[6] || (p)->fds_bits[7])
0133
0134 #define XFD_COPYSET(src,dst) \
0135 (dst)->fds_bits[0] = (src)->fds_bits[0]; \
0136 (dst)->fds_bits[1] = (src)->fds_bits[1]; \
0137 (dst)->fds_bits[2] = (src)->fds_bits[2]; \
0138 (dst)->fds_bits[3] = (src)->fds_bits[3]; \
0139 (dst)->fds_bits[4] = (src)->fds_bits[4]; \
0140 (dst)->fds_bits[5] = (src)->fds_bits[5]; \
0141 (dst)->fds_bits[6] = (src)->fds_bits[6]; \
0142 (dst)->fds_bits[7] = (src)->fds_bits[7];
0143
0144 #define XFD_ANDSET(dst,b1,b2) \
0145 (dst)->fds_bits[0] = ((b1)->fds_bits[0] & (b2)->fds_bits[0]); \
0146 (dst)->fds_bits[1] = ((b1)->fds_bits[1] & (b2)->fds_bits[1]); \
0147 (dst)->fds_bits[2] = ((b1)->fds_bits[2] & (b2)->fds_bits[2]); \
0148 (dst)->fds_bits[3] = ((b1)->fds_bits[3] & (b2)->fds_bits[3]); \
0149 (dst)->fds_bits[4] = ((b1)->fds_bits[4] & (b2)->fds_bits[4]); \
0150 (dst)->fds_bits[5] = ((b1)->fds_bits[5] & (b2)->fds_bits[5]); \
0151 (dst)->fds_bits[6] = ((b1)->fds_bits[6] & (b2)->fds_bits[6]); \
0152 (dst)->fds_bits[7] = ((b1)->fds_bits[7] & (b2)->fds_bits[7]);
0153
0154 #define XFD_ORSET(dst,b1,b2) \
0155 (dst)->fds_bits[0] = ((b1)->fds_bits[0] | (b2)->fds_bits[0]); \
0156 (dst)->fds_bits[1] = ((b1)->fds_bits[1] | (b2)->fds_bits[1]); \
0157 (dst)->fds_bits[2] = ((b1)->fds_bits[2] | (b2)->fds_bits[2]); \
0158 (dst)->fds_bits[3] = ((b1)->fds_bits[3] | (b2)->fds_bits[3]); \
0159 (dst)->fds_bits[4] = ((b1)->fds_bits[4] | (b2)->fds_bits[4]); \
0160 (dst)->fds_bits[5] = ((b1)->fds_bits[5] | (b2)->fds_bits[5]); \
0161 (dst)->fds_bits[6] = ((b1)->fds_bits[6] | (b2)->fds_bits[6]); \
0162 (dst)->fds_bits[7] = ((b1)->fds_bits[7] | (b2)->fds_bits[7]);
0163
0164 #define XFD_UNSET(dst,b1) \
0165 (dst)->fds_bits[0] &= ~((b1)->fds_bits[0]); \
0166 (dst)->fds_bits[1] &= ~((b1)->fds_bits[1]); \
0167 (dst)->fds_bits[2] &= ~((b1)->fds_bits[2]); \
0168 (dst)->fds_bits[3] &= ~((b1)->fds_bits[3]); \
0169 (dst)->fds_bits[4] &= ~((b1)->fds_bits[4]); \
0170 (dst)->fds_bits[5] &= ~((b1)->fds_bits[5]); \
0171 (dst)->fds_bits[6] &= ~((b1)->fds_bits[6]); \
0172 (dst)->fds_bits[7] &= ~((b1)->fds_bits[7]);
0173
0174 #else
0175 #include <sys/poll.h>
0176 #endif
0177
0178 #else
0179
0180 #define XFD_SETSIZE 256
0181 #ifndef FD_SETSIZE
0182 #define FD_SETSIZE XFD_SETSIZE
0183 #endif
0184 #include <X11/Xwinsock.h>
0185
0186 #define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
0187
0188 #define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count)
0189 #define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
0190 #define XFD_ANYSET(p) XFD_SETCOUNT(p)
0191
0192 #define XFD_COPYSET(src,dst) { \
0193 u_int __i; \
0194 FD_ZERO(dst); \
0195 for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
0196 XFD_FD(dst,__i) = XFD_FD(src,__i); \
0197 } \
0198 XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
0199 }
0200
0201 #define XFD_ANDSET(dst,b1,b2) { \
0202 u_int __i; \
0203 FD_ZERO(dst); \
0204 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
0205 if (FD_ISSET(XFD_FD(b1,__i), b2)) \
0206 FD_SET(XFD_FD(b1,__i), dst); \
0207 } \
0208 }
0209
0210 #define XFD_ORSET(dst,b1,b2) { \
0211 u_int __i; \
0212 XFD_COPYSET(b1,dst); \
0213 for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
0214 if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
0215 FD_SET(XFD_FD(b2,__i), dst); \
0216 } \
0217 }
0218
0219
0220 #define XFD_UNSET(dst,b1) { \
0221 u_int __i; \
0222 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
0223 FD_CLR(XFD_FD(b1,__i), dst); \
0224 } \
0225 }
0226
0227
0228
0229 #undef FD_SET
0230 #define FD_SET(fd,set) do { \
0231 if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
0232 XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
0233 } while(0)
0234
0235 #define getdtablesize() FD_SETSIZE
0236
0237 #endif
0238
0239 #endif