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 performs control operations on the epoll(7) instance
15       referred to by the file descriptor epfd.  It requests that  the  opera‐
16       tion op be performed for the target file descriptor, fd.
17
18       Valid values for the op argument are:
19
20       EPOLL_CTL_ADD
21              Register  the  target  file  descriptor fd on the epoll instance
22              referred to by the file descriptor epfd and associate the  event
23              event with the internal file linked to fd.
24
25       EPOLL_CTL_MOD
26              Change  the event event associated with the target file descrip‐
27              tor fd.
28
29       EPOLL_CTL_DEL
30              Remove (deregister) the target file descriptor fd from the epoll
31              instance  referred  to by epfd.  The event is ignored and can be
32              NULL (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 an error.
134              EPOLLEXCLUSIVE may be used only in an  EPOLL_CTL_ADD  operation;
135              attempts  to  employ  it  with EPOLL_CTL_MOD yield an error.  If
136              EPOLLEXCLUSIVE has been set using epoll_ctl(), then a subsequent
137              EPOLL_CTL_MOD on the same epfd, fd pair yields an error.  A call
138              to epoll_ctl() that specifies EPOLLEXCLUSIVE in events and spec‐
139              ifies  the  target  file descriptor fd as an epoll instance will
140              likewise fail.  The error in all of these cases is EINVAL.
141

RETURN VALUE

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

ERRORS

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

VERSIONS

186       epoll_ctl() was added to the kernel in version 2.6.
187

CONFORMING TO

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

NOTES

193       The epoll interface supports all file descriptors that support poll(2).
194

BUGS

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

SEE ALSO

214       epoll_create(2), epoll_wait(2), poll(2), epoll(7)
215

COLOPHON

217       This  page  is  part of release 4.15 of the Linux man-pages project.  A
218       description of the project, information about reporting bugs,  and  the
219       latest     version     of     this    page,    can    be    found    at
220       https://www.kernel.org/doc/man-pages/.
221
222
223
224Linux                             2017-09-15                      EPOLL_CTL(2)
Impressum