]> git.sesse.net Git - rdpsrv/blob - Xserver/include/Xpoll.h
Support RDP5 logon packets.
[rdpsrv] / Xserver / include / Xpoll.h
1 /* $XConsortium: Xpoll.h /main/6 1996/12/02 10:25:52 lehors $ */
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 /* AIX 4.2 fubar-ed <sys/select.h>, so go to heroic measures to get it */
48 #if defined(AIXV4) && !defined(NFDBITS)
49 #include <sys/select.h>
50 #endif
51 #include <X11/Xmd.h>
52 #ifdef CSRG_BASED
53 #include <sys/param.h>
54 # if BSD < 199103
55 typedef long fd_mask;
56 # endif
57 #endif
58
59 #define XFD_SETSIZE     256
60 #ifndef FD_SETSIZE
61 #define FD_SETSIZE      XFD_SETSIZE
62 #endif
63
64 #ifndef NBBY
65 #define NBBY    8               /* number of bits in a byte */
66 #endif
67
68 #ifndef NFDBITS
69 #define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */
70 #endif
71
72 #ifndef howmany
73 #define howmany(x,y)    (((x)+((y)-1))/(y))
74 #endif
75
76 #ifdef BSD
77 # if BSD < 198911       /* 198911 == OSF/1, 199103 == CSRG_BASED */
78 #  ifndef luna          /* and even though on LUNA BSD ==  43, it has it */
79 typedef struct fd_set {
80         fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
81 } fd_set;
82 #  endif
83 # endif
84 #endif
85
86 #ifdef hpux /* and perhaps old BSD ??? */
87 #define Select(n,r,w,e,t) select(n,(int*)r,(int*)w,(int*)e,(struct timeval*)t)
88 #else
89 #define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
90 #endif
91
92 #ifndef FD_SET
93 #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
94 #endif
95 #ifndef FD_CLR
96 #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
97 #endif
98 #ifndef FD_ISSET
99 #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
100 #endif
101 #ifndef FD_ZERO
102 #define FD_ZERO(p)      bzero((char *)(p), sizeof(*(p)))
103 #endif
104
105 /*
106  * The following macros are used by the servers only. There is an
107  * explicit assumption that the bit array in the fd_set is at least
108  * 256 bits long (8 32-bit words). This is true on most modern POSIX 
109  * systems. Note that this is merely an optimization for the servers
110  * based on assumptions about the way that file descripters are
111  * allocated on POSIX systems. 
112  *
113  * When porting X to new systems it is important to adjust these
114  * macros if the system has fewer than 256 bits in the fd_set bit
115  * array.
116  */
117 #define XFD_ANYSET(p) \
118                 ((p)->fds_bits[0] || (p)->fds_bits[1] || \
119                 (p)->fds_bits[2] || (p)->fds_bits[3] || \
120                 (p)->fds_bits[4] || (p)->fds_bits[5] || \
121                 (p)->fds_bits[6] || (p)->fds_bits[7])
122
123 #define XFD_COPYSET(src,dst) \
124                 (dst)->fds_bits[0] = (src)->fds_bits[0]; \
125                 (dst)->fds_bits[1] = (src)->fds_bits[1]; \
126                 (dst)->fds_bits[2] = (src)->fds_bits[2]; \
127                 (dst)->fds_bits[3] = (src)->fds_bits[3]; \
128                 (dst)->fds_bits[4] = (src)->fds_bits[4]; \
129                 (dst)->fds_bits[5] = (src)->fds_bits[5]; \
130                 (dst)->fds_bits[6] = (src)->fds_bits[6]; \
131                 (dst)->fds_bits[7] = (src)->fds_bits[7];
132
133 #define XFD_ANDSET(dst,b1,b2) \
134                 (dst)->fds_bits[0] = ((b1)->fds_bits[0] & (b2)->fds_bits[0]); \
135                 (dst)->fds_bits[1] = ((b1)->fds_bits[1] & (b2)->fds_bits[1]); \
136                 (dst)->fds_bits[2] = ((b1)->fds_bits[2] & (b2)->fds_bits[2]); \
137                 (dst)->fds_bits[3] = ((b1)->fds_bits[3] & (b2)->fds_bits[3]); \
138                 (dst)->fds_bits[4] = ((b1)->fds_bits[4] & (b2)->fds_bits[4]); \
139                 (dst)->fds_bits[5] = ((b1)->fds_bits[5] & (b2)->fds_bits[5]); \
140                 (dst)->fds_bits[6] = ((b1)->fds_bits[6] & (b2)->fds_bits[6]); \
141                 (dst)->fds_bits[7] = ((b1)->fds_bits[7] & (b2)->fds_bits[7]);
142
143 #define XFD_ORSET(dst,b1,b2) \
144                 (dst)->fds_bits[0] = ((b1)->fds_bits[0] | (b2)->fds_bits[0]); \
145                 (dst)->fds_bits[1] = ((b1)->fds_bits[1] | (b2)->fds_bits[1]); \
146                 (dst)->fds_bits[2] = ((b1)->fds_bits[2] | (b2)->fds_bits[2]); \
147                 (dst)->fds_bits[3] = ((b1)->fds_bits[3] | (b2)->fds_bits[3]); \
148                 (dst)->fds_bits[4] = ((b1)->fds_bits[4] | (b2)->fds_bits[4]); \
149                 (dst)->fds_bits[5] = ((b1)->fds_bits[5] | (b2)->fds_bits[5]); \
150                 (dst)->fds_bits[6] = ((b1)->fds_bits[6] | (b2)->fds_bits[6]); \
151                 (dst)->fds_bits[7] = ((b1)->fds_bits[7] | (b2)->fds_bits[7]);
152
153 #define XFD_UNSET(dst,b1) \
154                 (dst)->fds_bits[0] &= ~((b1)->fds_bits[0]); \
155                 (dst)->fds_bits[1] &= ~((b1)->fds_bits[1]); \
156                 (dst)->fds_bits[2] &= ~((b1)->fds_bits[2]); \
157                 (dst)->fds_bits[3] &= ~((b1)->fds_bits[3]); \
158                 (dst)->fds_bits[4] &= ~((b1)->fds_bits[4]); \
159                 (dst)->fds_bits[5] &= ~((b1)->fds_bits[5]); \
160                 (dst)->fds_bits[6] &= ~((b1)->fds_bits[6]); \
161                 (dst)->fds_bits[7] &= ~((b1)->fds_bits[7]);
162
163 #else /* USE_POLL */
164 #include <sys/poll.h>
165 #endif /* USE_POLL */
166
167 #else /* WIN32 */
168
169 #define XFD_SETSIZE     256
170 #ifndef FD_SETSIZE
171 #define FD_SETSIZE      XFD_SETSIZE
172 #endif
173 #include <X11/Xwinsock.h>
174
175 #define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
176
177 #define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count)
178 #define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
179 #define XFD_ANYSET(p)   XFD_SETCOUNT(p)
180
181 #define XFD_COPYSET(src,dst) { \
182     u_int __i; \
183     FD_ZERO(dst); \
184     for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
185         XFD_FD(dst,__i) = XFD_FD(src,__i); \
186     } \
187     XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
188 }
189
190 #define XFD_ANDSET(dst,b1,b2) { \
191     u_int __i; \
192     FD_ZERO(dst); \
193     for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
194         if (FD_ISSET(XFD_FD(b1,__i), b2)) \
195            FD_SET(XFD_FD(b1,__i), dst); \
196     } \
197 }
198
199 #define XFD_ORSET(dst,b1,b2) { \
200     u_int __i; \
201     XFD_COPYSET(b1,dst); \
202     for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
203         if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
204            FD_SET(XFD_FD(b2,__i), dst); \
205     } \
206 }
207
208 /* this one is really sub-optimal */
209 #define XFD_UNSET(dst,b1) { \
210     u_int __i; \
211     for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
212         FD_CLR(XFD_FD(b1,__i), dst); \
213     } \
214 }
215
216 /* we have to pay the price of having an array here, unlike with bitmasks
217    calling twice FD_SET with the same fd is not transparent, so be careful */
218 #undef FD_SET
219 #define FD_SET(fd,set) do { \
220     if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
221         XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
222 } while(0)
223
224 #define getdtablesize() FD_SETSIZE 
225
226 #endif /* WIN32 */
227
228 #endif /* _XPOLL_H_ */