This commit is contained in:
Michael Kerrisk 2008-02-28 16:04:59 +00:00
parent cb1de8d77d
commit 3bc917f6ca
1 changed files with 23 additions and 9 deletions

View File

@ -121,9 +121,9 @@ as an edge-triggered
.RB ( EPOLLET )
interface is as follows:
.RS
.TP
.TP 4
.B i
with non-blocking file descriptors
with non-blocking file descriptors; and
.TP
.B ii
by waiting for an event only after
@ -188,6 +188,7 @@ or
.BR write (2)
from where it stopped before.
.in +4n
.nf
struct epoll_event ev, *events;
@ -205,8 +206,10 @@ for (;;) {
setnonblocking(client);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = client;
if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, client, &ev) < 0) {
fprintf(stderr, "epoll set insertion error: fd=%d\\n",
if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, client, &ev)
== \-1) {
fprintf(stderr,
"epoll set insertion error: fd=%d\\n",
client);
return \-1;
}
@ -216,9 +219,12 @@ for (;;) {
}
}
.fi
.in
When used as an edge-triggered interface, for performance reasons, it is
possible to add the file descriptor inside the epoll interface
possible to add the file descriptor inside the
.B epoll
interface
.RB ( EPOLL_CTL_ADD )
once by specifying
.RB ( EPOLLIN | EPOLLOUT ).
@ -234,7 +240,9 @@ with
.SS Questions and Answers
.TP 4
.B Q0
What is the key used to distinguish the file descriptors in an epoll set?
What is the key used to distinguish the file descriptors in an
.B epoll
set?
.TP
.B A0
The key is the combination of the file descriptor number and
@ -243,7 +251,9 @@ the open file description
the kernel's internal representation of an open file).
.TP
.B Q1
What happens if you add the same file descriptor to an epoll set twice?
What happens if you add the same file descriptor to an
.B epoll
set twice?
.TP
.B A1
You will probably get
@ -312,7 +322,9 @@ call will fail
.RB ( EINVAL ).
However, you can add an
.B epoll
file descriptor inside another epoll file descriptor set.
file descriptor inside another
.B epoll
file descriptor set.
.TP
.B Q5
Can I send the
@ -461,7 +473,9 @@ The
API was introduced in Linux kernel 2.5.44.
Its interface should be finalized in Linux kernel 2.5.66.
.SH CONFORMING TO
The epoll API is Linux-specific.
The
.B epoll
API is Linux-specific.
Some other systems provide similar
mechanisms, for example, FreeBSD has
.IR kqueue ,