xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/sys/linux/epoll.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**
2  * D header file to interface with the Linux epoll API (http://man7.org/linux/man-pages/man7/epoll.7.html).
3  * Available since Linux 2.6
4  *
5  * Copyright: Copyright Adil Baig 2012.
6  * License : $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  * Authors  : Adil Baig (github.com/adilbaig)
8  */
9 module core.sys.linux.epoll;
10 
11 version (linux):
12 
13 import core.sys.posix.signal : sigset_t;
14 
15 extern (C):
16 @system:
17 @nogc:
18 nothrow:
19 @system:
20 
21 version (ARM)     version = ARM_Any;
22 version (AArch64) version = ARM_Any;
23 version (HPPA)    version = HPPA_Any;
24 version (MIPS32)  version = MIPS_Any;
25 version (MIPS64)  version = MIPS_Any;
26 version (PPC)     version = PPC_Any;
27 version (PPC64)   version = PPC_Any;
28 version (RISCV32) version = RISCV_Any;
29 version (RISCV64) version = RISCV_Any;
30 version (S390)    version = IBMZ_Any;
31 version (SPARC)   version = SPARC_Any;
32 version (SPARC64) version = SPARC_Any;
33 version (SystemZ) version = IBMZ_Any;
34 version (X86)     version = X86_Any;
35 version (X86_64)  version = X86_Any;
36 
37 enum
38 {
39     EPOLL_CLOEXEC  = 0x80000,
40     EPOLL_NONBLOCK = 0x800
41 }
42 
43 enum
44 {
45     EPOLLIN     = 0x001,
46     EPOLLPRI    = 0x002,
47     EPOLLOUT    = 0x004,
48     EPOLLRDNORM = 0x040,
49     EPOLLRDBAND = 0x080,
50     EPOLLWRNORM = 0x100,
51     EPOLLWRBAND = 0x200,
52     EPOLLMSG    = 0x400,
53     EPOLLERR    = 0x008,
54     EPOLLHUP    = 0x010,
55     EPOLLRDHUP  = 0x2000, // since Linux 2.6.17
56     EPOLLEXCLUSIVE = 1u << 28, // since Linux 4.5
57     EPOLLWAKEUP = 1u << 29,
58     EPOLLONESHOT = 1u << 30,
59     EPOLLET     = 1u << 31
60 }
61 
62 /**
63  * Valid opcodes ( "op" parameter ) to issue to epoll_ctl().
64  */
65 enum
66 {
67     EPOLL_CTL_ADD = 1, /// Add a file descriptor to the interface.
68     EPOLL_CTL_DEL = 2, /// Remove a file descriptor from the interface.
69     EPOLL_CTL_MOD = 3, /// Change file descriptor epoll_event structure.
70 }
71 
version(X86_Any)72 version (X86_Any)
73 {
74     align(1) struct epoll_event
75     {
76     align(1):
77         uint events;
78         epoll_data_t data;
79     }
80 }
81 else version (ARM_Any)
82 {
83     struct epoll_event
84     {
85         uint events;
86         epoll_data_t data;
87     }
88 }
89 else version (PPC_Any)
90 {
91     struct epoll_event
92     {
93         uint events;
94         epoll_data_t data;
95     }
96 }
97 else version (HPPA_Any)
98 {
99     struct epoll_event
100     {
101         uint events;
102         epoll_data_t data;
103     }
104 }
105 else version (MIPS_Any)
106 {
107     struct epoll_event
108     {
109         uint events;
110         epoll_data_t data;
111     }
112 }
113 else version (RISCV_Any)
114 {
115     struct epoll_event
116     {
117         uint events;
118         epoll_data_t data;
119     }
120 }
121 else version (SPARC_Any)
122 {
123     struct epoll_event
124     {
125         uint events;
126         epoll_data_t data;
127     }
128 }
129 else version (IBMZ_Any)
130 {
131     struct epoll_event
132     {
133         uint events;
134         epoll_data_t data;
135     }
136 }
137 else
138 {
139     static assert(false, "Platform not supported");
140 }
141 
142 union epoll_data_t
143 {
144     void *ptr;
145     int fd;
146     uint u32;
147     ulong u64;
148 }
149 
150 /**
151  * Creates an epoll instance.
152  *
153  * Params:
154  *   size = a hint specifying the number of file descriptors to be associated
155  *          with the new instance.  T
156  * Returns: an fd for the new instance. The fd returned by epoll_create() should
157  *          be closed with close().
158  * See_also: epoll_create1 (int flags)
159  */
160 int epoll_create (int size);
161 
162 /* Same as epoll_create but with an FLAGS parameter.  The unused SIZE
163    parameter has been dropped.  */
164 
165 /**
166  * Creates an epoll instance.
167  *
168  * Params:
169  *   flags = a specified flag. If flags is 0, then, other than the fact that the
170  *           obsolete size argument is dropped, epoll_create1() is the same as
171  *           epoll_create().
172  * Returns: an fd for the new instance. The fd returned by epoll_create() should
173  *          be closed with close().
174  * See_also: epoll_create (int size)
175  */
176 int epoll_create1 (int flags);
177 
178 /**
179  * Manipulate an epoll instance
180  *
181  * Params:
182  *   epfd = an epoll file descriptor instance
183  *   op = one of the EPOLL_CTL_* constants
184  *   fd = target file descriptor of the operation
185  *   event = describes which events the caller is interested in and any
186  *           associated user dat
187  * Returns: 0 in case of success, -1 in case of error ( the "errno" variable
188  *          will contain the specific error code )
189  */
190 int epoll_ctl (int epfd, int op, int fd, epoll_event *event);
191 
192 
193 /**
194  * Wait for events on an epoll instance.
195  *
196  *
197  * Params:
198  *   epfd = an epoll file descriptor instance
199  *   events = a buffer that will contain triggered events
200  *   maxevents = the maximum number of events to be returned ( usually size of
201  *               "events" )
202  *   timeout = specifies the maximum wait time in milliseconds (-1 == infinite)
203  *
204  * Returns: the number of triggered events returned in "events" buffer. Or -1 in
205  *          case of error with the "errno" variable set to the specific error
206  *          code.
207  */
208 int epoll_wait (int epfd, epoll_event *events, int maxevents, int timeout);
209 
210 /**
211  * Wait for events on an epoll instance
212  *
213  *
214  * Params:
215  *   epfd = an epoll file descriptor instance
216  *   events = a buffer that will contain triggered events
217  *   maxevents = the maximum number of events to be returned ( usually size of
218  *               "events" )
219  *   timeout = specifies the maximum wait time in milliseconds (-1 == infinite)
220  *   ss = a signal set. May be specified as `null`, in which case epoll_pwait() is
221  *        equivalent to epoll_wait().
222  *
223  * Returns: the number of triggered events returned in "events" buffer. Or -1 in
224  *          case of error with the "errno" variable set to the specific error
225  *          code.
226  */
227 int epoll_pwait (int epfd, epoll_event *events, int maxevents, int timeout,
228     const sigset_t *ss);
229