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
|
'\" te
.\" Copyright (c) 2014, Joyent, Inc. All Rights Reserved.
.\" Copyright 2020 Oxide Computer Company
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source. A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.TH EPOLL_CTL 3C "June 29, 2020"
.SH NAME
epoll_ctl \- control an epoll instance
.SH SYNOPSIS
.nf
#include <sys/epoll.h>
\fBint\fR \fBepoll_ctl\fR(\fBint\fR \fIepfd\fR, \fBint\fR \fIop\fR, \fBint\fR \fIfd\fR, \fBstruct epoll_event *\fR\fIevent\fR);
.fi
.SH DESCRIPTION
The \fBepoll_ctl()\fR function executes the operation specified by
\fIop\fR (as parameterized by \fIevent\fR) on the \fIepfd\fR epoll instance.
Valid values for \fIop\fR:
.sp
.ne 2
.na
\fBEPOLL_CTL_ADD\fR
.ad
.RS 12n
For the \fBepoll\fR(5) instance specified by \fIepfd\fR,
associate the file descriptor specified by \fIfd\fR with the event specified
by \fIevent\fR.
.RE
.sp
.ne 2
.na
\fBEPOLL_CTL_DEL\fR
.ad
.RS 12n
For the \fBepoll\fR(5) instance specified by \fIepfd\fR,
remove all event associations for the file descriptor specified by \fIfd\fR.
\fIevent\fR is ignored, and may be NULL.
.RE
.sp
.ne 2
.na
\fBEPOLL_CTL_MOD\fR
.ad
.RS 12n
For the \fBepoll\fR(5) instance specified by \fIepfd\fR, modify the event
association for the file descriptor specified by \fIfd\fR to be that
specified by \fIevent\fR.
.RE
The \fIevent\fR parameter has the following structure:
.in +4
.nf
typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;
struct epoll_event {
uint32_t events;
epoll_data_t data;
};
.fi
.in -4
The \fIdata\fR field specifies the datum to
be associated with the event and
will be returned via \fBepoll_wait\fR(3C).
The \fIevents\fR field denotes both the desired events (when specified via
\fBepoll_ctl()\fR) and the events that have occurred (when returned via
\fBepoll_wait\fR(3C)).
In either case, the
\fIevents\fR field is a bitmask constructed by a logical \fBOR\fR operation
of any combination of the following event flags:
.sp
.ne 2
.na
\fBEPOLLIN\fR
.ad
.RS 14n
Data other than high priority data may be read without blocking. For streams,
this flag is set in the returned \fIevents\fR even if the message is of
zero length.
.RE
.sp
.ne 2
.na
\fBEPOLLPRI\fR
.ad
.RS 14n
Normal data (priority band equals 0) may be read without blocking. For streams,
this flag is set in the returned \fIevents\fR even if the message is of zero
length.
.RE
.sp
.ne 2
.na
\fBEPOLLOUT\fR
.ad
.RS 14n
Normal data (priority band equals 0) may be written without blocking.
.RE
.sp
.ne 2
.na
\fBEPOLLRDNORM\fR
.ad
.RS 14n
Normal data (priority band equals 0) may be read without blocking. For streams,
this flag is set in the returned \fIrevents\fR even if the message is of
zero length.
.RE
.sp
.ne 2
.na
\fBEPOLLRDBAND\fR
.ad
.RS 14n
Data from a non-zero priority band may be read without blocking. For streams,
this flag is set in the returned \fIrevents\fR even if the message is of
zero length.
.RE
.sp
.ne 2
.na
\fBEPOLLWRNORM\fR
.ad
.RS 14n
The same as \fBEPOLLOUT\fR.
.RE
.sp
.ne 2
.na
\fBEPOLLWRBAND\fR
.ad
.RS 14n
Priority data (priority band > 0) may be written. This event only examines
bands that have been written to at least once.
.RE
.sp
.ne 2
.na
\fBEPOLLMSG\fR
.ad
.RS 14n
This exists only for backwards binary and source compatibility with Linux;
it has no meaning and is ignored.
.RE
.sp
.ne 2
.na
\fBEPOLLERR\fR
.ad
.RS 14n
An error has occurred on the device or stream. This flag is only valid in the
returned \fIevents\fR field.
.RE
.sp
.ne 2
.na
\fBEPOLLHUP\fR
.ad
.RS 14n
A hangup has occurred on the stream. This event and \fBEPOLLOUT\fR are mutually
exclusive; a stream can never be writable if a hangup has occurred. However,
this event and \fBEPOLLIN\fR, \fBEPOLLRDNORM\fR, \fBEPOLLRDBAND\fR,
\fBEPOLLRDHUP\fR or
\fBEPOLLPRI\fR are not mutually exclusive. This flag is only valid in the
\fIevents\fR field returned from \fBepoll_wait\fR(3C); it is not used in the
\fIevents\fR field specified via \fBepoll_ctl()\fR.
.RE
.sp
.ne 2
.na
\fBEPOLLRDHUP\fR
.ad
.RS 14n
The stream socket peer shutdown the writing half of the connection and no
further data will be readable via the socket. This event is not mutually
exclusive with \fBEPOLLIN\fR.
.RE
.sp
.ne 2
.na
\fBEPOLLEXCLUSIVE\fR
.ad
.RS 14n
This is present for binary compatibility and is effectively a no-op on illumos.
The flag was added to Linux in v4.5 to provide a means to mitigate thundering
herd problems when multiple epoll instances contain the same event source. Set
on a specified event source during \fBEPOLL_CTL_ADD\fR (and not allowed with
\fBEPOLL_CTL_MOD\fR), it indicates that epoll should attempt to limit the scope
of pollers woken when a shared target resource changes state. All pollers
without the flag set in the event will be notified and one \fIor more\fR of
those with it set will be as well.
.RE
.sp
.ne 2
.na
\fBEPOLLWAKEUP\fR
.ad
.RS 14n
This exists only for backwards binary and source compatibility with Linux;
it has no meaning and is ignored.
.RE
.sp
.ne 2
.na
\fBEPOLLONESHOT\fR
.ad
.RS 14n
Sets the specified event to be in one-shot mode, whereby the event association
with the \fBepoll\fR(5) instance specified by \fIepfd\fR is removed atomically
as the event is returned via \fBepoll_wait\fR(3C). Use of this mode allows
for resolution of some of the
races inherent in multithreaded use of \fBepoll_wait\fR(3C).
.RE
.sp
.ne 2
.na
\fBEPOLLET\fR
.ad
.RS 14n
Sets the specified event to be edge-triggered mode instead of the default
mode of level-triggered. In this mode, events will be induced by
transitions on an event source rather than the state of the event source.
While perhaps superficially appealing, this mode introduces several new
potential failure modes for user-level software and should be used
with caution.
.RE
.SH RETURN VALUES
Upon successful completion, \fBepoll_ctl()\fR returns 0.
If an error occurs, -1 is returned and errno is set to indicate
the error.
.SH ERRORS
\fBepoll_ctl()\fR will fail if:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
\fIepfd\fR is not a valid file descriptor.
.RE
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The memory associated with \fIevent\fR was not mapped.
.RE
.sp
.ne 2
.na
\fB\fBEEXIST\fR\fR
.ad
.RS 10n
The operation specified was \fBEPOLL_CTL_ADD\fR and the specified file
descriptor is already associated with an event for the specified
\fBepoll\fR(5) instance.
.RE
.sp
.ne 2
.na
\fB\fBENOENT\fR\fR
.ad
.RS 10n
The operation specified was \fBEPOLL_CTL_MOD\fR or \fBEPOLL_CTL_DEL\fR and
the specified file descriptor is not associated with an event for the
specified \fBepoll\fR(5) instance.
.RE
.sp
.SH NOTES
The \fBepoll\fR(5) facility is implemented for purposes of offering
compatibility for Linux-borne applications; native
applications should continue to prefer using event ports via the
\fBport_create\fR(3C), \fBport_associate\fR(3C) and \fBport_get\fR(3C)
interfaces. See \fBepoll\fR(5) for compatibility details and restrictions.
.SH SEE ALSO
\fBepoll_create\fR(3C), \fBepoll_wait\fR(3C),
\fBport_create\fR(3C), \fBport_associate\fR(3C), \fBport_get\fR(3C),
\fBepoll\fR(5)
|