1 /**
2  * D header file for POSIX.
3  *
4  * Copyright: Copyright Sean Kelly 2005 - 2009.
5  * License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
6  * Authors:   Sean Kelly
7  * Standards: The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
8  */
9 
10 /*          Copyright Sean Kelly 2005 - 2009.
11  * Distributed under the Boost Software License, Version 1.0.
12  *    (See accompanying file LICENSE or copy at
13  *          http://www.boost.org/LICENSE_1_0.txt)
14  */
15 module core.sys.posix.poll;
16 
17 import core.sys.posix.config;
18 
19 version (OSX)
20     version = Darwin;
21 else version (iOS)
22     version = Darwin;
23 else version (TVOS)
24     version = Darwin;
25 else version (WatchOS)
26     version = Darwin;
27 
28 version (Posix):
29 extern (C):
30 nothrow:
31 @nogc:
32 
33 //
34 // XOpen (XSI)
35 //
36 /*
37 struct pollfd
38 {
39     int     fd;
40     short   events;
41     short   revents;
42 }
43 
44 nfds_t
45 
46 int poll(pollfd[], nfds_t, int);
47 */
48 
49 version (CRuntime_Glibc)
50 {
51     struct pollfd
52     {
53         int     fd;
54         short   events;
55         short   revents;
56     }
57 
58     alias c_ulong nfds_t;
59 
60     int poll(pollfd*, nfds_t, int);
61 }
62 else version (Darwin)
63 {
64     struct pollfd
65     {
66         int     fd;
67         short   events;
68         short   revents;
69     }
70 
71     alias uint nfds_t;
72 
73     int poll(pollfd*, nfds_t, int);
74 }
75 else version (FreeBSD)
76 {
77     alias uint nfds_t;
78 
79     struct pollfd
80     {
81         int     fd;
82         short   events;
83         short   revents;
84     }
85 
86     int poll(pollfd*, nfds_t, int);
87 }
88 else version (NetBSD)
89 {
90     alias uint nfds_t;
91 
92     struct pollfd
93     {
94         int     fd;
95         short   events;
96         short   revents;
97     }
98 
99     int poll(pollfd*, nfds_t, int);
100 }
101 else version (OpenBSD)
102 {
103     alias uint nfds_t;
104 
105     struct pollfd
106     {
107         int     fd;
108         short   events;
109         short   revents;
110     }
111 
112     int poll(pollfd*, nfds_t, int);
113 }
114 else version (DragonFlyBSD)
115 {
116     alias uint nfds_t;
117 
118     struct pollfd
119     {
120         int     fd;
121         short   events;
122         short   revents;
123     }
124 
125     int poll(pollfd*, nfds_t, int);
126 }
127 else version (Solaris)
128 {
129     alias c_ulong nfds_t;
130 
131     struct pollfd
132     {
133         int     fd;
134         short   events;
135         short   revents;
136     }
137 
138     int poll(pollfd*, nfds_t, int);
139 }
140 else version (CRuntime_Bionic)
141 {
142     struct pollfd
143     {
144         int     fd;
145         short   events;
146         short   revents;
147     }
148 
149     alias uint nfds_t;
150 
151     int poll(pollfd*, nfds_t, c_long);
152 }
153 else version (CRuntime_Musl)
154 {
155     struct pollfd
156     {
157         int     fd;
158         short   events;
159         short   revents;
160     }
161 
162     alias uint nfds_t;
163 
164     int poll(pollfd*, nfds_t, c_long);
165 }
166 else version (CRuntime_UClibc)
167 {
168     struct pollfd
169     {
170         int     fd;
171         short   events;
172         short   revents;
173     }
174 
175     alias c_ulong nfds_t;
176 
177     int poll(pollfd*, nfds_t, int);
178 }
179 else
180 {
181     static assert(false, "Unsupported platform");
182 }
183 
184 /*
185 POLLIN
186 POLLRDNORM
187 POLLRDBAND
188 POLLPRI
189 POLLOUT
190 POLLWRNORM
191 POLLWRBAND
192 POLLERR
193 POLLHUP
194 POLLNVAL
195 */
196 
197 version (linux)
198 {
199     enum
200     {
201         POLLIN      = 0x001,
202         POLLRDNORM  = 0x040,
203         POLLRDBAND  = 0x080,
204         POLLPRI     = 0x002,
205         POLLOUT     = 0x004,
206         POLLWRNORM  = 0x100,
207         POLLWRBAND  = 0x200,
208         POLLERR     = 0x008,
209         POLLHUP     = 0x010,
210         POLLNVAL    = 0x020,
211     }
212 }
213 else version (Darwin)
214 {
215     enum
216     {
217         POLLIN      = 0x0001,
218         POLLPRI     = 0x0002,
219         POLLOUT     = 0x0004,
220         POLLRDNORM  = 0x0040,
221         POLLWRNORM  = POLLOUT,
222         POLLRDBAND  = 0x0080,
223         POLLWRBAND  = 0x0100,
224         POLLEXTEND  = 0x0200,
225         POLLATTRIB  = 0x0400,
226         POLLNLINK   = 0x0800,
227         POLLWRITE   = 0x1000,
228         POLLERR     = 0x0008,
229         POLLHUP     = 0x0010,
230         POLLNVAL    = 0x0020,
231 
232         POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
233                         POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
234     }
235 }
236 else version (FreeBSD)
237 {
238     enum
239     {
240         POLLIN      = 0x0001,
241         POLLPRI     = 0x0002,
242         POLLOUT     = 0x0004,
243         POLLRDNORM  = 0x0040,
244         POLLWRNORM  = POLLOUT,
245         POLLRDBAND  = 0x0080,
246         POLLWRBAND  = 0x0100,
247         //POLLEXTEND  = 0x0200,
248         //POLLATTRIB  = 0x0400,
249         //POLLNLINK   = 0x0800,
250         //POLLWRITE   = 0x1000,
251         POLLERR     = 0x0008,
252         POLLHUP     = 0x0010,
253         POLLNVAL    = 0x0020,
254 
255         POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
256         POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
257     }
258 }
259 else version (NetBSD)
260 {
261     enum
262     {
263         POLLIN      = 0x0001,
264         POLLPRI     = 0x0002,
265         POLLOUT     = 0x0004,
266         POLLRDNORM  = 0x0040,
267         POLLWRNORM  = POLLOUT,
268         POLLRDBAND  = 0x0080,
269         POLLWRBAND  = 0x0100,
270         //POLLEXTEND  = 0x0200,
271         //POLLATTRIB  = 0x0400,
272         //POLLNLINK   = 0x0800,
273         //POLLWRITE   = 0x1000,
274         POLLERR     = 0x0008,
275         POLLHUP     = 0x0010,
276         POLLNVAL    = 0x0020,
277 
278         POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
279         POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
280     }
281 }
282 else version (OpenBSD)
283 {
284     enum
285     {
286         POLLIN      = 0x0001,
287         POLLPRI     = 0x0002,
288         POLLOUT     = 0x0004,
289         POLLRDNORM  = 0x0040,
290         POLLNORM    = POLLRDNORM,
291         POLLWRNORM  = POLLOUT,
292         POLLRDBAND  = 0x0080,
293         POLLWRBAND  = 0x0100,
294         POLLERR     = 0x0008,
295         POLLHUP     = 0x0010,
296         POLLNVAL    = 0x0020,
297 
298         POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
299         POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
300     }
301 }
302 else version (DragonFlyBSD)
303 {
304     enum
305     {
306         POLLIN      = 0x0001,
307         POLLPRI     = 0x0002,
308         POLLOUT     = 0x0004,
309         POLLRDNORM  = 0x0040,
310         POLLWRNORM  = POLLOUT,
311         POLLRDBAND  = 0x0080,
312         POLLWRBAND  = 0x0100,
313         //POLLEXTEND  = 0x0200,
314         //POLLATTRIB  = 0x0400,
315         //POLLNLINK   = 0x0800,
316         //POLLWRITE   = 0x1000,
317         POLLERR     = 0x0008,
318         POLLHUP     = 0x0010,
319         POLLNVAL    = 0x0020,
320 
321         POLLSTANDARD = (POLLIN|POLLPRI|POLLOUT|POLLRDNORM|POLLRDBAND|
322         POLLWRBAND|POLLERR|POLLHUP|POLLNVAL)
323     }
324 }
325 else version (Solaris)
326 {
327     enum
328     {
329         POLLIN      = 0x0001,
330         POLLPRI     = 0x0002,
331         POLLOUT     = 0x0004,
332         POLLRDNORM  = 0x0040,
333         POLLWRNORM  = POLLOUT,
334         POLLRDBAND  = 0x0080,
335         POLLWRBAND  = 0x0100,
336         POLLERR     = 0x0008,
337         POLLHUP     = 0x0010,
338         POLLNVAL    = 0x0020,
339     }
340 }
341 else
342 {
343     static assert(false, "Unsupported platform");
344 }