summaryrefslogtreecommitdiff
path: root/static/netbsd/man2/epoll.2
blob: 667a2b5a6c2a0758afe357f37cea2fada8fb41e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
.\"	$NetBSD: epoll.2,v 1.2 2023/07/28 23:41:16 wiz Exp $
.\"
.\" Copyright (c) 2023 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Theodore Preduta.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd July 19, 2023
.Dt EPOLL 2
.Os
.Sh NAME
.Nm epoll ,
.Nm epoll_event ,
.Nm epoll_data ,
.Nm epoll_data_t ,
.Nm epoll_create ,
.Nm epoll_create1 ,
.Nm epoll_ctl ,
.Nm epoll_wait ,
.Nm epoll_pwait ,
.Nm epoll_pwait2
.Nd event notification mechanism
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In sys/epoll.h
.Bd -literal
union epoll_data {
	void		*ptr;
	int		fd;
	uint32_t	u32;
	uint64_t	u64;
};

typedef union epoll_data	epoll_data_t;

struct epoll_event {
	uint32_t	events;
	epoll_data_t	data;
};
.Ed
.Pp
.Ft int
.Fn epoll_create "int size"
.Ft int
.Fn epoll_create1 "int flags"
.Ft int
.Fn epoll_ctl "int epfd" "int op" "int fd" "struct epoll_event *event"
.Ft int
.Fn epoll_wait "int epfd" "struct epoll_event *events" "int maxevents" "int timeout"
.Ft int
.Fn epoll_pwait "int epfd" "struct epoll_event *events" "int maxevents" "int timeout" "const sigset_t *sigmask"
.Ft int
.Fn epoll_pwait2 "int epfd" "struct epoll_event *events" "int maxevents" "const struct timespec *timeout" "const sigset_t *sigmask"
.Sh DESCRIPTION
.Nm
provides a similar facility to both
.Xr select 2
and
.Xr kqueue 2 :
it allows for the examination of file descriptors to see if they are available
for reading/writing.
.Pp
The
.Va epoll_event
structure consists of two fields,
.Va events
and
.Va data .
The
.Va data
field is passed through the kernel and is intended to be used to identify the
event.
When used with
.Fn epoll_ctl ,
the
.Va events
field consists of a mask of the events that the
.Nm
instance should watch for, and when being used with
.Fn epoll_wait ,
.Fn epoll_pwait ,
and
.Fn epoll_pwait2
consists of a mask of the events that occurred.
The following are possible values for
.Va events :
.Bl -tag -width EPOLLONESHOT
.It Dv EPOLLIN
Watch for
.Xr read 2
operations.
.It Dv EPOLLOUT
Watch for
.Xr write 2
operations.
.It Dv EPOLLRDHUP
Watch for a peer closed connection.
.It Dv EPOLLERR
Watch for error conditions.
.It Dv EPOLLET
This option modifies the other set bits of
.Va events .
When set, the events described by other bits in
.Va events
are only triggered when the state change.
Otherwise the events are considered triggered whenever the condition is true.
.It Dv EPOLLONESHOT
Remove this event once it is retrieved once.
.El
.Pp
.Fn epoll_create
and
.Fn epoll_create1
both create an
.Nm
instance.
The
.Fa size
argument specified for
.Fn epoll_create
exists so that the
.Nx
function has the same signature as the Linux system call of the same name.
.Fa size
must be positive, but is otherwise unused.
Additionally, optionally,
.Dv EPOLL_CLOEXEC
may be specified in the
.Fa flags
of
.Fn epoll_create1
to set the
.Xr close 2
on
.Xr exec 3
flag.
.Pp
.Fn epoll_ctl
is used to make changes to the given
.Nm
instance based on the provided
.Fa op .
Possible values for
.Fa op
are:
.Bl -tag -width EPOLL_CTL_ADD
.It Dv EPOLL_CTL_ADD
Register interest of
.Fa fd
on the
.Fa epfd
for the events specified in
.Fa event .
.It Dv EPOLL_CTL_MOD
Modify the events registered for
.Fa fd
to those specified in
.Fa event .
.It Dv EPOLL_CTL_DEL
Deregister
.Fa fd
from the
.Nm
instance specified in
.Fa epfd .
Note that
.Fa event
is completely ignored in this case.
.El
.Pp
.Fn epoll_wait ,
.Fn epoll_pwait ,
and
.Fn epoll_pwait2
provide the ability to wait for up to
.Fa maxevents
which are stored in the buffer pointed to by
.Fa events .
For
.Fn epoll_wait
and
.Fn epoll_pwait ,
a timeout may be specified in
.Fa timeout
in milliseconds.
If no timeout is desired, -1 should be specified in
.Fa timeout .
For
.Fn epoll_pwait2
if no timeout is desired
.Fa timeout
should be specified as
.Dv NULL .
Additionally,
a sigmask may be specified to
.Fn epoll_pwait
and
.Fn epoll_pwait2
in
.Fa sigmask
to set the sigmask while
.Nm
waits for events.
.Pp
Note that
.Nm
is not intended to be used by native
.Nx
applications.
Instead it is only intended to used as a means to help port software originally
written for Linux to
.Nx .
.Sh RETURN VALUES
.Fn epoll_create
and
.Fn epoll_create1
both return a file descriptor when successful.
.Pp
.Fn epoll_ctl
returns zero when successful.
.Pp
.Fn epoll_wait ,
.Fn epoll_pwait ,
and
.Fn epoll_pwait2
return the number of events written to
.Fa events
when successful.
Note that zero is written to when
.Fa timeout
expires and no events were available.
.Pp
When any of the above fail, -1 is returned and
.Fa errno
is set.
.Sh ERRORS
The
.Fn epoll_create
and
.Fn epoll_create1
functions fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
.Fa size
is not positive.
.Pp
Bits other than
.Dv EPOLL_CLOEXEC
are provided in
.Fa flags .
.It Bq Er EMFILE
The per-process descriptor table is full.
.It Bq Er ENFILE
The system file table is full.
.It Bq Er ENOMEM
The kernel failed to allocate enough memory for a
.Nm
instance.
.El
.Pp
The
.Fn epoll_ctl
function fails if:
.Bl -tag -width Er
.It Bq Er EBADF
.Fa epfd
or
.Fa fd
is not a valid file descriptor.
.It Bq Er EEXIST
.Fa op
is
.Dv EPOLL_CTL_ADD
and
.Fa fd
was already previously added via
.Dv EPOLL_CTL_ADD .
.It Bq Er EINVAL
.Fa epfd
is not a file descriptor for an
.Nm
instance.
.Pp
.Fa epfd
and
.Fa fd
represent the same
.Nm
instance.
.It Bq Er ELOOP
.Fa op
is
.Dv EPOLL_CTL_ADD
and adding
.Fa fd
would result in a circular loop of
.Nm
instances.
.It Bq Er ENOENT
.Fa op
is
.Dv EPOLL_CTL_MOD
or
.Dv EPOLL_CTL_DEL
and
.Fa fd
was not previously added with
.Dv EPOLL_CTL_ADD .
.It Bq Er ENOMEM
The kernel failed to allocate enough memory for
.Fa op .
.It Bq Er EPERM
.Fa fd
does not support
.Nm epoll .
.El
.Pp
The
.Fn epoll_wait ,
.Fn epoll_pwait ,
and
.Fn epoll_pwait2
functions fail if:
.Bl -tag -width Er
.It Bq Er EBADF
.Fa epfd
is not a valid file descriptor.
.It Bq Er EFAULT
The area provided in
.Fa events
failed to be written to.
.It Bq Er EINTR
A signal was delivered before any events became available and
.Fa timeout
expired.
.It Bq Er EINVAL
.Fa epfd
is not a valid
.Nm
file descriptor.
.Pp
.Fa maxevents
is less than or equal to zero.
.El
.Sh SEE ALSO
.Xr kqueue 2 ,
.Xr poll 2 ,
.Xr select 2
.Sh HISTORY
The
.Nm
functions and types are designed to be compatible with the Linux system calls of
the same name.
.Sh CAVEATS
The
.Nm
facility is not intended to be used in conjunction with
.Xr kqueue 2 .
.Pp
Unlike Linux's
.Nm ,
the
.Nx
version does not survive a
.Xr fork 2 .