Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:32

0001 /* $Xorg: Xpoll.h,v 1.3 2000/08/18 04:05:44 coskrey Exp $ */
0002 
0003 /*
0004 
0005 Copyright 1994, 1998  The Open Group
0006 
0007 All Rights Reserved.
0008 
0009 The above copyright notice and this permission notice shall be included
0010 in all copies or substantial portions of the Software.
0011 
0012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
0013 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0014 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0015 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
0016 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0017 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0018 OTHER DEALINGS IN THE SOFTWARE.
0019 
0020 Except as contained in this notice, the name of The Open Group shall
0021 not be used in advertising or otherwise to promote the sale, use or
0022 other dealings in this Software without prior written authorization
0023 from The Open Group.
0024 
0025 */
0026 /* $XFree86: xc/include/Xpoll.h,v 3.7 2000/09/19 12:46:05 eich Exp $ */
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 /* DGUX  -- No sys/select in Intel DG/ux */
0044 #include <sys/time.h> 
0045 #include <sys/types.h>
0046 #include <unistd.h>
0047 #endif
0048 
0049 #ifdef __QNX__  /* Make sure we get 256 bit select masks */
0050 #define FD_SETSIZE 256
0051 #include <sys/select.h>
0052 #endif
0053 
0054 /* AIX 4.2 fubar-ed <sys/select.h>, so go to heroic measures to get it */
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       /* number of bits in a byte */
0073 #endif
0074 
0075 #ifndef NFDBITS
0076 #define NFDBITS (sizeof(fd_mask) * NBBY)    /* bits per mask */
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   /* 198911 == OSF/1, 199103 == CSRG_BASED */
0085 #  ifndef luna      /* and even though on LUNA BSD ==  43, it has it */
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 /* and perhaps old BSD ??? */
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 /* HPUX 9.x and earlier */
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  * The following macros are used by the servers only. There is an
0118  * explicit assumption that the bit array in the fd_set is at least
0119  * 256 bits long (8 32-bit words). This is true on most modern POSIX 
0120  * systems. Note that this is merely an optimization for the servers
0121  * based on assumptions about the way that file descripters are
0122  * allocated on POSIX systems. 
0123  *
0124  * When porting X to new systems it is important to adjust these
0125  * macros if the system has fewer than 256 bits in the fd_set bit
0126  * array.
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 /* USE_POLL */
0175 #include <sys/poll.h>
0176 #endif /* USE_POLL */
0177 
0178 #else /* WIN32 */
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 /* this one is really sub-optimal */
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 /* we have to pay the price of having an array here, unlike with bitmasks
0228    calling twice FD_SET with the same fd is not transparent, so be careful */
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 /* WIN32 */
0238 
0239 #endif /* _XPOLL_H_ */