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