1EPOLL_CTL(2)               Linux Programmer's Manual              EPOLL_CTL(2)
2
3
4

NAME

6       epoll_ctl - control interface for an epoll file descriptor
7

SYNOPSIS

9       #include <sys/epoll.h>
10
11       int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
12

DESCRIPTION

14       This  system  call  is  used  to  add, modify, or remove entries in the
15       interest list of the epoll(7) instance referred to by the file descrip‐
16       tor  epfd.  It requests that the operation op be performed for the tar‐
17       get file descriptor, fd.
18
19       Valid values for the op argument are:
20
21       EPOLL_CTL_ADD
22              Add fd to the interest list and associate the settings specified
23              in event with the internal file linked to fd.
24
25       EPOLL_CTL_MOD
26              Change  the  settings associated with fd in the interest list to
27              the new settings specified in event.
28
29       EPOLL_CTL_DEL
30              Remove (deregister) the  target  file  descriptor  fd  from  the
31              interest  list.   The  event argument is ignored and can be NULL
32              (but see BUGS below).
33
34       The event argument describes the object linked to the  file  descriptor
35       fd.  The struct epoll_event is defined as:
36
37           typedef union epoll_data {
38               void        *ptr;
39               int          fd;
40               uint32_t     u32;
41               uint64_t     u64;
42           } epoll_data_t;
43
44           struct epoll_event {
45               uint32_t     events;      /* Epoll events */
46               epoll_data_t data;        /* User data variable */
47           };
48
49       The events member is a bit mask composed by ORing together zero or more
50       of the following available event types:
51
52       EPOLLIN
53              The associated file is available for read(2) operations.
54
55       EPOLLOUT
56              The associated file is available for write(2) operations.
57
58       EPOLLRDHUP (since Linux 2.6.17)
59              Stream socket peer closed connection, or shut down writing  half
60              of connection.  (This flag is especially useful for writing sim‐
61              ple code to detect peer shutdown when using Edge Triggered moni‐
62              toring.)
63
64       EPOLLPRI
65              There  is  an exceptional condition on the file descriptor.  See
66              the discussion of POLLPRI in poll(2).
67
68       EPOLLERR
69              Error condition happened  on  the  associated  file  descriptor.
70              This event is also reported for the write end of a pipe when the
71              read end has been closed.  epoll_wait(2) will always report  for
72              this event; it is not necessary to set it in events.
73
74       EPOLLHUP
75              Hang   up   happened   on   the   associated   file  descriptor.
76              epoll_wait(2) will always wait for this event; it is not  neces‐
77              sary to set it in events.
78
79              Note that when reading from a channel such as a pipe or a stream
80              socket, this event merely indicates that the peer closed its end
81              of the channel.  Subsequent reads from the channel will return 0
82              (end of file) only after all outstanding data in the channel has
83              been consumed.
84
85       EPOLLET
86              Sets  the  Edge  Triggered  behavior  for  the  associated  file
87              descriptor.  The default behavior for epoll is Level  Triggered.
88              See  epoll(7) for more detailed information about Edge and Level
89              Triggered event distribution architectures.
90
91       EPOLLONESHOT (since Linux 2.6.2)
92              Sets the one-shot behavior for the associated  file  descriptor.
93              This  means that after an event is pulled out with epoll_wait(2)
94              the associated file descriptor is  internally  disabled  and  no
95              other  events will be reported by the epoll interface.  The user
96              must call epoll_ctl()  with  EPOLL_CTL_MOD  to  rearm  the  file
97              descriptor with a new event mask.
98
99       EPOLLWAKEUP (since Linux 3.5)
100              If  EPOLLONESHOT  and  EPOLLET are clear and the process has the
101              CAP_BLOCK_SUSPEND capability, ensure that the  system  does  not
102              enter  "suspend"  or  "hibernate" while this event is pending or
103              being processed.  The event is considered as  being  "processed"
104              from  the  time  when  it is returned by a call to epoll_wait(2)
105              until the next call to epoll_wait(2) on the same  epoll(7)  file
106              descriptor,  the closure of that file descriptor, the removal of
107              the event file descriptor with EPOLL_CTL_DEL, or the clearing of
108              EPOLLWAKEUP  for  the  event file descriptor with EPOLL_CTL_MOD.
109              See also BUGS.
110
111       EPOLLEXCLUSIVE (since Linux 4.5)
112              Sets an exclusive wakeup mode for the epoll file descriptor that
113              is  being  attached  to  the target file descriptor, fd.  When a
114              wakeup event occurs and  multiple  epoll  file  descriptors  are
115              attached  to  the  same target file using EPOLLEXCLUSIVE, one or
116              more of the epoll file descriptors will receive  an  event  with
117              epoll_wait(2).   The  default in this scenario (when EPOLLEXCLU‐
118              SIVE is not set) is for all epoll file descriptors to receive an
119              event.   EPOLLEXCLUSIVE  is  thus useful for avoiding thundering
120              herd problems in certain scenarios.
121
122              If the same file descriptor is in multiple epoll instances, some
123              with  the  EPOLLEXCLUSIVE  flag, and others without, then events
124              will be provided to all epoll instances  that  did  not  specify
125              EPOLLEXCLUSIVE, and at least one of the epoll instances that did
126              specify EPOLLEXCLUSIVE.
127
128              The following  values  may  be  specified  in  conjunction  with
129              EPOLLEXCLUSIVE:  EPOLLIN,  EPOLLOUT,  EPOLLWAKEUP,  and EPOLLET.
130              EPOLLHUP and EPOLLERR can also be specified,  but  this  is  not
131              required:  as  usual,  these  events are always reported if they
132              occur, regardless of  whether  they  are  specified  in  events.
133              Attempts  to specify other values in events yield the error EIN‐
134              VAL.
135
136              EPOLLEXCLUSIVE may be used only in an  EPOLL_CTL_ADD  operation;
137              attempts  to  employ  it  with EPOLL_CTL_MOD yield an error.  If
138              EPOLLEXCLUSIVE has been set using epoll_ctl(), then a subsequent
139              EPOLL_CTL_MOD on the same epfd, fd pair yields an error.  A call
140              to epoll_ctl() that specifies EPOLLEXCLUSIVE in events and spec‐
141              ifies  the  target  file descriptor fd as an epoll instance will
142              likewise fail.  The error in all of these cases is EINVAL.
143

RETURN VALUE

145       When successful, epoll_ctl()  returns  zero.   When  an  error  occurs,
146       epoll_ctl() returns -1 and errno is set appropriately.
147

ERRORS

149       EBADF  epfd or fd is not a valid file descriptor.
150
151       EEXIST op  was  EPOLL_CTL_ADD,  and  the supplied file descriptor fd is
152              already registered with this epoll instance.
153
154       EINVAL epfd is not an epoll file descriptor, or fd is the same as epfd,
155              or  the  requested  operation op is not supported by this inter‐
156              face.
157
158       EINVAL An invalid event type was specified along with EPOLLEXCLUSIVE in
159              events.
160
161       EINVAL op was EPOLL_CTL_MOD and events included EPOLLEXCLUSIVE.
162
163       EINVAL op  was EPOLL_CTL_MOD and the EPOLLEXCLUSIVE flag has previously
164              been applied to this epfd, fd pair.
165
166       EINVAL EPOLLEXCLUSIVE was specified in event and fd refers to an  epoll
167              instance.
168
169       ELOOP  fd  refers to an epoll instance and this EPOLL_CTL_ADD operation
170              would result in a circular loop of  epoll  instances  monitoring
171              one another.
172
173       ENOENT op  was EPOLL_CTL_MOD or EPOLL_CTL_DEL, and fd is not registered
174              with this epoll instance.
175
176       ENOMEM There was insufficient memory to handle the requested op control
177              operation.
178
179       ENOSPC The  limit  imposed  by  /proc/sys/fs/epoll/max_user_watches was
180              encountered while trying to register (EPOLL_CTL_ADD) a new  file
181              descriptor  on  an  epoll  instance.   See  epoll(7) for further
182              details.
183
184       EPERM  The target file fd does not support epoll.  This error can occur
185              if fd refers to, for example, a regular file or a directory.
186

VERSIONS

188       epoll_ctl() was added to the kernel in version 2.6.
189

CONFORMING TO

191       epoll_ctl()  is  Linux-specific.   Library support is provided in glibc
192       starting with version 2.3.2.
193

NOTES

195       The epoll interface supports all file descriptors that support poll(2).
196

BUGS

198       In kernel versions before 2.6.9, the EPOLL_CTL_DEL operation required a
199       non-null pointer in event, even though this argument is ignored.  Since
200       Linux 2.6.9, event can be specified as NULL when  using  EPOLL_CTL_DEL.
201       Applications  that  need  to be portable to kernels before 2.6.9 should
202       specify a non-null pointer in event.
203
204       If EPOLLWAKEUP is specified in flags, but the caller does not have  the
205       CAP_BLOCK_SUSPEND  capability,  then  the  EPOLLWAKEUP flag is silently
206       ignored.  This unfortunate behavior is necessary  because  no  validity
207       checks were performed on the flags argument in the original implementa‐
208       tion, and the addition of the EPOLLWAKEUP with a check that caused  the
209       call  to fail if the caller did not have the CAP_BLOCK_SUSPEND capabil‐
210       ity caused a breakage in at least one existing  user-space  application
211       that  happened  to randomly (and uselessly) specify this bit.  A robust
212       application  should  therefore   double   check   that   it   has   the
213       CAP_BLOCK_SUSPEND capability if attempting to use the EPOLLWAKEUP flag.
214

SEE ALSO

216       epoll_create(2), epoll_wait(2), poll(2), epoll(7)
217

COLOPHON

219       This  page  is  part of release 5.04 of the Linux man-pages project.  A
220       description of the project, information about reporting bugs,  and  the
221       latest     version     of     this    page,    can    be    found    at
222       https://www.kernel.org/doc/man-pages/.
223
224
225
226Linux                             2019-03-06                      EPOLL_CTL(2)
Impressum