]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/epoll_ctl.2
epoll_ctl.2: Document ELOOP error for circular monitoring loops
[thirdparty/man-pages.git] / man2 / epoll_ctl.2
CommitLineData
fea681da 1.\" Copyright (C) 2003 Davide Libenzi
4366109b 2.\" Davide Libenzi <davidel@xmailserver.org>
fea681da 3.\"
f0008367 4.\" %%%LICENSE_START(GPLv2+_SW_3_PARA)
fea681da
MK
5.\" This program is free software; you can redistribute it and/or modify
6.\" it under the terms of the GNU General Public License as published by
7.\" the Free Software Foundation; either version 2 of the License, or
8.\" (at your option) any later version.
9.\"
10.\" This program is distributed in the hope that it will be useful,
11.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
12.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.\" GNU General Public License for more details.
14.\"
68fa4398
MK
15.\" You should have received a copy of the GNU General Public
16.\" License along with this manual; if not, see
17.\" <http://www.gnu.org/licenses/>.
8ff7380d 18.\" %%%LICENSE_END
fea681da 19.\"
67d2c687 20.TH EPOLL_CTL 2 2015-05-07 "Linux" "Linux Programmer's Manual"
fea681da 21.SH NAME
d9cb0d7d 22epoll_ctl \- control interface for an epoll file descriptor
fea681da
MK
23.SH SYNOPSIS
24.B #include <sys/epoll.h>
25.sp
52e87bbe
MK
26.BI "int epoll_ctl(int " epfd ", int " op ", int " fd \
27", struct epoll_event *" event );
fea681da 28.SH DESCRIPTION
78d1cbde
MK
29This system call performs control operations on the
30.BR epoll (7)
31instance
a58b3360
MK
32referred to by the file descriptor
33.IR epfd .
34It requests that the operation
0daa9e92 35.I op
7829230a 36be performed for the target file descriptor,
fea681da 37.IR fd .
7829230a
MK
38
39Valid values for the
40.I op
e87feb33 41argument are:
7829230a
MK
42.TP
43.B EPOLL_CTL_ADD
44Register the target file descriptor
45.I fd
46on the
47.B epoll
48instance referred to by the file descriptor
49.I epfd
50and associate the event
51.I event
52with the internal file linked to
53.IR fd .
54.TP
55.B EPOLL_CTL_MOD
56Change the event
57.I event
58associated with the target file descriptor
59.IR fd .
60.TP
61.B EPOLL_CTL_DEL
62Remove (deregister) the target file descriptor
63.I fd
64from the
65.B epoll
66instance referred to by
67.IR epfd .
68The
69.I event
70is ignored and can be NULL (but see BUGS below).
71.PP
fea681da 72The
0daa9e92 73.I event
7829230a 74argument describes the object linked to the file descriptor
fea681da
MK
75.IR fd .
76The
8478ee02 77.I struct epoll_event
e87feb33 78is defined as:
fea681da 79.sp
a08ea57c 80.in +4n
fea681da 81.nf
cf0a9ace 82typedef union epoll_data {
6ebde978
MK
83 void *ptr;
84 int fd;
2677bc5c
MK
85 uint32_t u32;
86 uint64_t u64;
cf0a9ace 87} epoll_data_t;
fea681da 88
cf0a9ace 89struct epoll_event {
2677bc5c 90 uint32_t events; /* Epoll events */
6ebde978 91 epoll_data_t data; /* User data variable */
cf0a9ace 92};
fea681da 93.fi
a08ea57c 94.in
fea681da
MK
95
96The
97.I events
03323a99 98member is a bit mask composed using the following available event
c781c53c 99types:
fea681da
MK
100.TP
101.B EPOLLIN
102The associated file is available for
103.BR read (2)
104operations.
105.TP
106.B EPOLLOUT
107The associated file is available for
108.BR write (2)
109operations.
110.TP
64d6219c 111.BR EPOLLRDHUP " (since Linux 2.6.17)"
c13182ef 112Stream socket peer closed connection,
04706fd7 113or shut down writing half of connection.
c13182ef 114(This flag is especially useful for writing simple code to detect
04706fd7
MK
115peer shutdown when using Edge Triggered monitoring.)
116.TP
fea681da
MK
117.B EPOLLPRI
118There is urgent data available for
119.BR read (2)
120operations.
121.TP
122.B EPOLLERR
123Error condition happened on the associated file descriptor.
3d9a2200
MK
124.BR epoll_wait (2)
125will always wait for this event; it is not necessary to set it in
126.IR events .
fea681da
MK
127.TP
128.B EPOLLHUP
129Hang up happened on the associated file descriptor.
3d9a2200
MK
130.BR epoll_wait (2)
131will always wait for this event; it is not necessary to set it in
132.IR events .
ea735ea8
MK
133Note that when reading from a channel such as a pipe or a stream socket,
134this event merely indicates that the peer closed its end of the channel.
135Subsequent reads from the channel will return 0 (end of file)
136only after all outstanding data in the channel has been consumed.
fea681da
MK
137.TP
138.B EPOLLET
d9bfdb9c
MK
139Sets the Edge Triggered behavior for the associated file descriptor.
140The default behavior for
fea681da 141.B epoll
c13182ef
MK
142is Level Triggered.
143See
2315114c 144.BR epoll (7)
704a18f0 145for more detailed information about Edge and Level Triggered event
fea681da
MK
146distribution architectures.
147.TP
64d6219c 148.BR EPOLLONESHOT " (since Linux 2.6.2)"
d9bfdb9c 149Sets the one-shot behavior for the associated file descriptor.
019934ed 150This means that after an event is pulled out with
fea681da
MK
151.BR epoll_wait (2)
152the associated file descriptor is internally disabled and no other events
153will be reported by the
154.B epoll
c13182ef
MK
155interface.
156The user must call
2777b1ca 157.BR epoll_ctl ()
fea681da
MK
158with
159.B EPOLL_CTL_MOD
3b777aff 160to rearm the file descriptor with a new event mask.
573f05ef
N
161.TP
162.BR EPOLLWAKEUP " (since Linux 3.5)"
1bc86e8a 163.\" commit 4d7e30d98939a0340022ccd49325a3d70f7e0238
573f05ef
N
164If
165.B EPOLLONESHOT
166and
167.B EPOLLET
168are clear and the process has the
169.B CAP_BLOCK_SUSPEND
1bc86e8a 170capability,
573f05ef
N
171ensure that the system does not enter "suspend" or
172"hibernate" while this event is pending or being processed.
1bc86e8a
MK
173The event is considered as being "processed" from the time
174when it is returned by a call to
573f05ef
N
175.BR epoll_wait (2)
176until the next call to
177.BR epoll_wait (2)
178on the same
179.BR epoll (7)
c835f12b
N
180file descriptor,
181the closure of that file descriptor,
182the removal of the event file descriptor with
183.BR EPOLL_CTL_DEL ,
184or the clearing of
185.B EPOLLWAKEUP
186for the event file descriptor with
187.BR EPOLL_CTL_MOD .
8ab32b47 188See also BUGS.
47297adb 189.SH RETURN VALUE
c13182ef 190When successful,
2777b1ca 191.BR epoll_ctl ()
c13182ef
MK
192returns zero.
193When an error occurs,
2777b1ca 194.BR epoll_ctl ()
fea681da
MK
195returns \-1 and
196.I errno
197is set appropriately.
198.SH ERRORS
199.TP
200.B EBADF
fea681da 201.I epfd
2cfa66cf
MK
202or
203.I fd
3d9a2200
MK
204is not a valid file descriptor.
205.TP
206.B EEXIST
207.I op
682edefb
MK
208was
209.BR EPOLL_CTL_ADD ,
210and the supplied file descriptor
0daa9e92 211.I fd
a58b3360 212is already registered with this epoll instance.
fea681da
MK
213.TP
214.B EINVAL
0daa9e92 215.I epfd
fea681da
MK
216is not an
217.B epoll
3d9a2200
MK
218file descriptor,
219or
0daa9e92 220.I fd
3d9a2200
MK
221is the same as
222.IR epfd ,
223or the requested operation
fea681da
MK
224.I op
225is not supported by this interface.
226.TP
813596e5
MK
227.B ELOOP
228.I fd
229refers to an epoll instance and this
230.B EPOLL_CTL_ADD
231operation would result in a circular loop of epoll instances
232monitoring one another.
233.TP
3d9a2200
MK
234.B ENOENT
235.I op
682edefb 236was
0daa9e92 237.B EPOLL_CTL_MOD
682edefb
MK
238or
239.BR EPOLL_CTL_DEL ,
240and
0daa9e92 241.I fd