epollのヘルプ・マニュアル
日本語 英語
epoll --help
man epoll
EPOLL(7) Linux Programmer’s Manual EPOLL(7)
名前
epoll - I/O イベント通知機能
書式
#include
説明
epoll は poll(2) の一種であり、エッジトリガインタフェースとレベルトリガ
インタフェースのどちらとしても使用することができ、監視するファイルデ ィ
スクリプタの数が多い場合にも使用できる。 epoll インスタンスの作成や管理
を行うために以下のシステムコールが提供されている:
* epoll インスタンスは epoll_create(2) で作成される。 epoll_create(2)
は 作成した epoll インスタンスを参照するファイルディスクリプタを返す
。 (もっと新しい epoll_create1(2) では、 epoll_create(2) の機能が 拡
張されている)。
* 特定のファイルディスクリプタに対する監視内容を epoll_ctl(2) で登録す
る。 epoll インスタンスに現在登録されているファイルディスクリプタ の
集合は epoll 集合と呼ばれることもある。
* 最後に epoll_wait(2) で実際のイベント待ちを開始する。
レベルトリガとエッジトリガ
epoll イベント配送 (distribution) インタフェースは、エッジトリガ (ET)
としてもレベルトリガ (LT) としても動作させることができる。二つの配送 機
構の違いは、次のように説明できる。このようなシナリオが起こったとしよう:
1. パイプの読み込み側を表すファイルディスクリプタ (rfd) が epoll インス
タンスに登録される。
2. パイプへ書き込むプログラムが 2 kB のデータをパイプの書き込み側へ書き
込む。
3. epoll_wait(2) を呼び出すと、読み込み可能 (ready) なファイルディス ク
リプタとして rfd が返る。
4. パイプから読み出すプログラムが、1 kB のデータを rfd から読み出す。
5. epoll_wait(2) の呼び出しが行われる。
rfd フ ァ イルディスクリプタが EPOLLET フラグ (エッジトリガ) を使って
epoll に追加されていると、利用可能なデータがファイル入力バッファにま だ
存 在するにもかかわらずステップ 5 の epoll_wait(2) の呼び出しでハングす
る可能性がある。その一方で、リモートの接続先 (peer) は既に送られたデ ー
タ に基づいて応答を期待しているかもしれない。このようなことが起こる理由
は、エッジトリガイベント配送では、モニタしているファイルでイベントが 起
ったときにのみイベントが配送されるためである。したがって、ステップ 5 で
は、呼び出し側は結果的に入力バッファ内にすで存在するデータを待つこと に
な るかもしれない。上記の例では、 2 で行われた書き込みによって rfd に関
するイベントが生成され、 3 でイベントが消費 (consume) される。 4 で行わ
れ る読み込み操作では、全部のバッファデータを消費しないので、ステップ 5
で行われる epoll_wait(2) の呼び出しが無期限に停止 (block) するかもし れ
ない。
EPOLLET フラグを採用するアプリケーションでは、インタフェースはブロック
しない (non-blocking) ファイルディスクリプタを使うべきである。これは 、
ブ ロックされる読み込みや書き込みによって、複数のファイルディスクリプタ
を扱うタスクが停止してしまうのを避けるためである。 epoll をエッジトリガ
(EPOLLET) インタフェースとして使うために提案される方法は以下の通りであ
る。
i ブロックしないファイルディスクリプタと共に使う。
ii read(2) または write(2) が EAGAIN を返した後でのみ、イベント
を待つ。
一方、レベルトリガインタフェースとして使う場合
(こちらがデフォルトである、 EPOLLET が指定されなかった場合)、 epoll は
単に高速な poll(2) であり、使い方が同じなので、 poll(2) が使われてい る
ところではどこでも使用することができる。
エッジトリガを使った場合でも、複数のデータを受信すると複数の epoll イベ
ントが生成されるので、呼び出し側には EPOLLONESHOT フラグを指定するオ プ
シ ョンがある。このフラグは epoll に対して、 epoll_wait(2) によるイベン
トを受信した後で、関連するファイルディスクリプタを無効にさせる。 EPOL-
LONESHOT フラグが指定された場合、 epoll_ctl(2) に EPOLL_CTL_MOD を指定
してファイルディスクリプタを再度使用できるようにするのは、呼び出し側 の
責任である。
/proc インタフェース
epoll が消費するカーネルメモリの量を制限するために、以下のインタフェー
スを使用することができる。
/proc/sys/fs/epoll/max_user_watches (Linux 2.6.28 以降)
このファイルは、あるユーザがシステム上の全ての epoll イン
ス タンスに登録できるファイルディスクリプタの総数の上限を
規定する。この上限は実ユーザ ID 単位である。登録された フ
ァイルディスクリプタ 1 つが消費するメモリ量は、 32 ビット
カーネルでおよそ 90 バイト、 64 ビットカーネルで お よ そ
160 バイトである。現在のところ、 max_user_watches のデフ
ォルト値は、利用可能なメモリ下限の 1/25 (4%) であり、登録
で消費されるメモリ量 (バイト単位) で割った値となる。
おすすめな使用例
レ ベルトリガインタフェースとして使用するときの epoll の使い方は
poll(2) と同じである。しかしエッジトリガとして使う場合は、アプリ
ケ ーションのイベントループでストール (stall) しないように、使い
方をより明確にしておく必要がある。この例では、リスナはブロックし
な いソケットであり、 listen(2) が呼ばれている。関数 do_use_fd()
は、 read(2) または write(2) によって EAGAIN が返されるまでは 、
新しい準備済みのファイルディスクリプタを使う。イベント駆動ステー
トマシンアプリケーションは、 EAGAIN を受信した後、カレントの状態
を 記録しておくべきである。これにより、次の do_use_fd() 呼び出し
のときに、以前に停止したところから read(2) または write(2) を 継
続することができる。
#define MAX_EVENTS 10
struct epoll_event ev, events[MAX_EVENTS];
int listen_sock, conn_sock, nfds, epollfd;
/* Set up listening socket, 'listen_sock' (socket(),
bind(), listen()) */
epollfd = epoll_create(10);
if (epollfd == -1) {
perror("epoll_create");
exit(EXIT_FAILURE);
}
ev.events = EPOLLIN;
ev.data.fd = listen_sock;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {
perror("epoll_ctl: listen_sock");
exit(EXIT_FAILURE);
}
for (;;) {
nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
if (nfds == -1) {
perror("epoll_pwait");
exit(EXIT_FAILURE);
}
for (n = 0; n < nfds; ++n) {
if (events[n].data.fd == listen_sock) {
conn_sock = accept(listen_sock,
(struct sockaddr *) &local, &addrlen);
if (conn_sock == -1) {
perror("accept");
exit(EXIT_FAILURE);
}
setnonblocking(conn_sock);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = conn_sock;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,
&ev) == -1) {
perror("epoll_ctl: conn_sock");
exit(EXIT_FAILURE);
}
} else {
do_use_fd(events[n].data.fd);
}
}
}
エッジトリガインタフェースとして使う場合、性能上の理由により、一
度 (EPOLLIN|EPOLLOUT) を指定してから (EPOLL_CTL_ADD で) ファイル
デ ィスクリプタを epoll インタフェースに追加することができる。こ
れにより、 epoll_ctl(2) に EPOLL_CTL_MOD を指定して呼び出すこ と
で EPOLLIN と EPOLLOUT の連続的な切り替えが避けられる。
質問と解答
Q0 epoll 集合内の登録されたファイルディスクリプタを区別するには
、何をキーとして使えばよいか?
A0 キーはファイルディスクリプタ番号とオープンファイル記述 (open
file description) の組である (オープンファイル記述は "open
file handle" とも呼ばれ、オープンされたファイルのカーネル の
内部表現である)。
Q1 1 つの epoll インスタンスに同じファイルディスクリプタを 2 回
登録するとどうなるか?
A1 たぶん EEXIST を受け取るだろう。しかしながら、同じ epoll イ
ンスタンスに対して複製されたディスクリプタを追加することは可
能である (dup(2), dup2(2), fcntl(2) F_DUPFD など)。複製し た
ファイルディスクリプタを異なる events マスクで登録すれば、イ
ベントをフィルタリングするのにこの機能は有用な手法である。
Q2 2 つの epoll インスタンスが同じファイルディスクリプタを待 ち
受けることは可能か?もし可能であれば、イベントは両方の epoll
ファイルディスクリプタに報告されるか?
A2 イベントは両方に報告される。しかしながら、これを正しく扱うに
は注意深くプログラミングする必要があるかもしれない。
Q3 epoll ファイルディスクリプタ自身は poll/epoll/select が可能
か?
A3 可能である。 epoll ファイルディスクリプタに処理待ちのイベ ン
トがある場合は、読み出し可能だと通知されることだろう。
Q4 epoll ファイルディスクリプタを自身のファイルディスクリプタ集
合に入れようとするとどうなるか?
A4 epoll_ctl(2) の呼び出しは (EINVAL で) 失敗するだろう。ただし
epoll ファイルディスクリプタを他の epoll ファイルディスクリ
プタ集合の内部に追加することは可能である。
Q5 epoll ファイルディスクリプタを Unix ドメインソケットで他のプ
ロセスに送ることは可能か?
A5 可能だが、これをすることに意味はない。なぜなら、受信側のプロ
セスが epoll 集合内のファイルディスクリプタのコピーを持っ て
いないからである。
Q6 ファイルディスクリプタをクローズすると、そのファイルディスク
リプタは全ての epoll 集合から自動的に削除されるか?
A6 削除されるが、以下の点に注意が必要である。ファイルディスクリ
プタはオープンファイル記述 (open(2) 参照) への参照である。デ
ィスクリプタの複製を dup(2), dup2(2), fcntl(2) の F_DUPFD や
fork(2) 経由で行う度に、同じオープンファイル記述を参照する新
規のファイルディスクリプタが生成される。オープンファイル記述
自体は、自身を参照する全てのファイルディスクリプタがクローズ
されるまで存在し続ける。ファイルディスクリプタが epoll 集 合
から削除されるのは、対応するオープンファイル記述を参照してい
る全てのファイルディスクリプタがクローズさ れ た 後 で あ る
(epoll_ctl() EPOLL_CTL_DEL を使ってそのディスクリプタを明示
的に削除した場合にも削除される)。このことは、 epoll 集合に属
しているあるファイルディスクリプタをクローズした後であっても
、同じファイル記述を参照する他のファイルディスクリプタがオー
プンされている間は、クローズしたファイルディスクリプタ宛にイ
ベントが報告される可能性があるということを意味する。
Q7 2 つ以上のイベントが epoll_wait(2) コールの間に発生した場 合
、それらはまとめて報告されるか、それとも別々に報告されるか?
A7 まとめて報告されるだろう。
Q8 ファイルディスクリプタに対する操作は、既に集められているがま
だ報告されていないイベントに影響するか?
A8 既存のファイルディスクリプタに対して 2 つの操作を行うことが
できる。この場合、削除には意味がない。変更すると、使用可能な
I/O が再び読み込まれる。
Q9 EPOLLET フラグ (エッジトリガ動作) を使っている場合、 EAGAIN
を受け取るまで、継続してファイルディスクリプタを読み書きする
必要があるか?
A9 epoll_wait(2) からイベントを受け取ることは、そのファイルディ
スクリプタが要求された I/O 操作に対して準備済みである、と い
う こ と を ユ ー ザ に示すものである。次の (ブロックしない)
read/write で EAGAIN を受け取るまではファイルディスクリプ タ
は準備済みであると考えなければならない。そのファイルディスク
リプタをいつどのように使うかは、全くユーザに任されてる。
パケット指向やトークン指向のファイル (例えば、データグラムソ
ケット、 canonical モードの端末) では、読み込み用 / 書き込み
用の I/O 空間の末尾を検知する唯一の方法は EAGAIN になるま で
read/write を行うことである。
ストリーム指向のファイル (例えば、パイプ、FIFO、ストリームソ
ケット) では、読み込み用 / 書き込み用の I/O 空間が使い尽くさ
れた状態は、対象となるファイルディスクリプタから読み込んだデ
ータ量または書き込んだデータ量をチェックすることでも検知でき
る 。例えば、ある特定の量のデータを読み込むために read(2) を
呼んだときに、 read(2) が返したバイト数がそれより少なかっ た
場 合、そのファイルディスクリプタの読み込み用 I/O 空間が使い
尽くされたことが分かる。 write(2) を使って書き込みをするとき
も、同じことが言える (監視しているファイルディスクリプタが常
にストリーム指向のファイルを参照していることを保証できない場
合には、後者の手法の使用を避けること)。
ありがちな落とし穴と回避方法
o 飢餓 (starvation) (エッジトリガ)
大 き な I/O 空 間がある場合、その I/O 空間のデータを全て処理
(drain) しようとすると、他のファイルが処理されず、飢餓を発生させ
ることがある (この問題は epoll に固有のものではない)。
こ の 問 題 の解決法は、準備済み状態のリストを管理して、関連する
data 構造体の中でファイルディスクリプタが利用可能であるとマー ク
することである。それによって、利用可能なすべてのファイルの中でど
のファイルを処理する必要があるかを憶えることができ、しかも順番に
処 理 (round robin) することができる。既に利用可能であるファイル
ディスクリプタに対してそれ以後に受け取るイベントを無視することも
できる。
o イベントキャッシュを使っている場合
イ ベントキャッシュを使っている場合、または epoll_wait(2) から返
された全てのファイルディスクリプタを格納している場合、クローズさ
れたことを動的にマークする (つまり前のイベントの処理によってマー
クされる) 方法を提供すべきである。 epoll_wait(2) から 100 個のイ
ベントを受け取り、イベント #47 ではある条件でイベント #13 が閉じ
られると仮定する。イベント #13 の構造体を削除しファイルディス ク
リプタを close(2) すると、イベントキャッシュはそのファイルディス
クリプタを待つイベントが存在するといって、混乱が起きる。
この問題を解決する 1 つの方法は、イベント 47 の処理をしている 間
に 、 フ ァ イルディスクリプタ 13 を削除して close(2) するために
epoll_ctl(EPOLL_CTL_DEL) を呼び出し、関連付けられた data 構造 体
を削除済みとマークして、クリーンアップリストにリンクすることであ
る。バッチ処理の中でファイルディスクリプタ 13 についての他のイベ
ントを見つけた場合、そのファイルディスクリプタが以前に削除された
ものであると分かるので、混乱は起きない。
バージョン
epoll API は Linux カーネル 2.5.44 に導入された。 glibc でのサポ
ートはバージョン 2.3.2 で追加された。
準拠
epoll API は Linux 固有である。他のシステムでも同様の機構が提供
されている場合がある。例えば、FreeBSD の kqueue や Solaris の
/dev/poll などである。
関連項目
epoll_create(2), epoll_create1(2), epoll_ctl(2), epoll_wait(2)
Linux 2009-02-01 EPOLL(7)
EPOLL(7) Linux Programmer’s Manual EPOLL(7)
NAME
epoll - I/O event notification facility
SYNOPSIS
#include
DESCRIPTION
epoll is a variant of poll(2) that can be used either as an edge-trig-
gered or a level-triggered interface and scales well to large numbers
of watched file descriptors. The following system calls are provided
to create and manage an epoll instance:
* An epoll instance created by epoll_create(2), which returns a file
descriptor referring to the epoll instance. (The more recent
epoll_create1(2) extends the functionality of epoll_create(2).)
* Interest in particular file descriptors is then registered via
epoll_ctl(2). The set of file descriptors currently registered on
an epoll instance is sometimes called an epoll set.
* Finally, the actual wait is started by epoll_wait(2).
Level-Triggered and Edge-Triggered
The epoll event distribution interface is able to behave both as edge-
triggered (ET) and as level-triggered (LT). The difference between the
two mechanisms can be described as follows. Suppose that this scenario
happens:
1. The file descriptor that represents the read side of a pipe (rfd) is
registered on the epoll instance.
2. A pipe writer writes 2 kB of data on the write side of the pipe.
3. A call to epoll_wait(2) is done that will return rfd as a ready file
descriptor.
4. The pipe reader reads 1 kB of data from rfd.
5. A call to epoll_wait(2) is done.
If the rfd file descriptor has been added to the epoll interface using
the EPOLLET (edge-triggered) flag, the call to epoll_wait(2) done in
step 5 will probably hang despite the available data still present in
the file input buffer; meanwhile the remote peer might be expecting a
response based on the data it already sent. The reason for this is
that edge-triggered mode only delivers events when changes occur on the
monitored file descriptor. So, in step 5 the caller might end up wait-
ing for some data that is already present inside the input buffer. In
the above example, an event on rfd will be generated because of the
write done in 2 and the event is consumed in 3. Since the read opera-
tion done in 4 does not consume the whole buffer data, the call to
epoll_wait(2) done in step 5 might block indefinitely.
An application that employs the EPOLLET flag should use non-blocking
file descriptors to avoid having a blocking read or write starve a task
that is handling multiple file descriptors. The suggested way to use
epoll as an edge-triggered (EPOLLET) interface is as follows:
i with non-blocking file descriptors; and
ii by waiting for an event only after read(2) or write(2)
return EAGAIN.
By contrast, when used as a level-triggered interface (the default,
when EPOLLET is not specified), epoll is simply a faster poll(2), and
can be used wherever the latter is used since it shares the same seman-
tics.
Since even with edge-triggered epoll, multiple events can be generated
upon receipt of multiple chunks of data, the caller has the option to
specify the EPOLLONESHOT flag, to tell epoll to disable the associated
file descriptor after the receipt of an event with epoll_wait(2). When
the EPOLLONESHOT flag is specified, it is the caller’s responsibility
to rearm the file descriptor using epoll_ctl(2) with EPOLL_CTL_MOD.
/proc interfaces
The following interfaces can be used to limit the amount of kernel mem-
ory consumed by epoll:
/proc/sys/fs/epoll/max_user_watches (since Linux 2.6.28)
This specifies a limit on the total number of file descriptors
that a user can register across all epoll instances on the sys-
tem. The limit is per real user ID. Each registered file
descriptor costs roughly 90 bytes on a 32-bit kernel, and
roughly 160 bytes on a 64-bit kernel. Currently, the default
value for max_user_watches is 1/25 (4%) of the available low
memory, divided by the registration cost in bytes.
Example for Suggested Usage
While the usage of epoll when employed as a level-triggered interface
does have the same semantics as poll(2), the edge-triggered usage
requires more clarification to avoid stalls in the application event
loop. In this example, listener is a non-blocking socket on which lis-
ten(2) has been called. The function do_use_fd() uses the new ready
file descriptor until EAGAIN is returned by either read(2) or write(2).
An event-driven state machine application should, after having received
EAGAIN, record its current state so that at the next call to
do_use_fd() it will continue to read(2) or write(2) from where it
stopped before.
#define MAX_EVENTS 10
struct epoll_event ev, events[MAX_EVENTS];
int listen_sock, conn_sock, nfds, epollfd;
/* Set up listening socket, 'listen_sock' (socket(),
bind(), listen()) */
epollfd = epoll_create(10);
if (epollfd == -1) {
perror("epoll_create");
exit(EXIT_FAILURE);
}
ev.events = EPOLLIN;
ev.data.fd = listen_sock;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {
perror("epoll_ctl: listen_sock");
exit(EXIT_FAILURE);
}
for (;;) {
nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
if (nfds == -1) {
perror("epoll_pwait");
exit(EXIT_FAILURE);
}
for (n = 0; n < nfds; ++n) {
if (events[n].data.fd == listen_sock) {
conn_sock = accept(listen_sock,
(struct sockaddr *) &local, &addrlen);
if (conn_sock == -1) {
perror("accept");
exit(EXIT_FAILURE);
}
setnonblocking(conn_sock);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = conn_sock;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock,
&ev) == -1) {
perror("epoll_ctl: conn_sock");
exit(EXIT_FAILURE);
}
} else {
do_use_fd(events[n].data.fd);
}
}
}
When used as an edge-triggered interface, for performance reasons, it
is possible to add the file descriptor inside the epoll interface
(EPOLL_CTL_ADD) once by specifying (EPOLLIN|EPOLLOUT). This allows you
to avoid continuously switching between EPOLLIN and EPOLLOUT calling
epoll_ctl(2) with EPOLL_CTL_MOD.
Questions and Answers
Q0 What is the key used to distinguish the file descriptors registered
in an epoll set?
A0 The key is the combination of the file descriptor number and the
open file description (also known as an "open file handle", the
kernel’s internal representation of an open file).
Q1 What happens if you register the same file descriptor on an epoll
instance twice?
A1 You will probably get EEXIST. However, it is possible to add a
duplicate (dup(2), dup2(2), fcntl(2) F_DUPFD) descriptor to the
same epoll instance. This can be a useful technique for filtering
events, if the duplicate file descriptors are registered with dif-
ferent events masks.
Q2 Can two epoll instances wait for the same file descriptor? If so,
are events reported to both epoll file descriptors?
A2 Yes, and events would be reported to both. However, careful pro-
gramming may be needed to do this correctly.
Q3 Is the epoll file descriptor itself poll/epoll/selectable?
A3 Yes. If an epoll file descriptor has events waiting then it will
indicate as being readable.
Q4 What happens if one attempts to put an epoll file descriptor into
its own file descriptor set?
A4 The epoll_ctl(2) call will fail (EINVAL). However, you can add an
epoll file descriptor inside another epoll file descriptor set.
Q5 Can I send an epoll file descriptor over a Unix domain socket to
another process?
A5 Yes, but it does not make sense to do this, since the receiving
process would not have copies of the file descriptors in the epoll
set.
Q6 Will closing a file descriptor cause it to be removed from all
epoll sets automatically?
A6 Yes, but be aware of the following point. A file descriptor is a
reference to an open file description (see open(2)). Whenever a
descriptor is duplicated via dup(2), dup2(2), fcntl(2) F_DUPFD, or
fork(2), a new file descriptor referring to the same open file
description is created. An open file description continues to
exist until all file descriptors referring to it have been closed.
A file descriptor is removed from an epoll set only after all the
file descriptors referring to the underlying open file description
have been closed (or before if the descriptor is explicitly removed
using epoll_ctl() EPOLL_CTL_DEL). This means that even after a
file descriptor that is part of an epoll set has been closed,
events may be reported for that file descriptor if other file
descriptors referring to the same underlying file description
remain open.
Q7 If more than one event occurs between epoll_wait(2) calls, are they
combined or reported separately?
A7 They will be combined.
Q8 Does an operation on a file descriptor affect the already collected
but not yet reported events?
A8 You can do two operations on an existing file descriptor. Remove
would be meaningless for this case. Modify will re-read available
I/O.
Q9 Do I need to continuously read/write a file descriptor until EAGAIN
when using the EPOLLET flag (edge-triggered behavior) ?
A9 Receiving an event from epoll_wait(2) should suggest to you that
such file descriptor is ready for the requested I/O operation. You
must consider it ready until the next (non-blocking) read/write
yields EAGAIN. When and how you will use the file descriptor is
entirely up to you.
For packet/token-oriented files (e.g., datagram socket, terminal in
canonical mode), the only way to detect the end of the read/write
I/O space is to continue to read/write until EAGAIN.
For stream-oriented files (e.g., pipe, FIFO, stream socket), the
condition that the read/write I/O space is exhausted can also be
detected by checking the amount of data read from / written to the
target file descriptor. For example, if you call read(2) by asking
to read a certain amount of data and read(2) returns a lower number
of bytes, you can be sure of having exhausted the read I/O space
for the file descriptor. The same is true when writing using
write(2). (Avoid this latter technique if you cannot guarantee
that the monitored file descriptor always refers to a stream-ori-
ented file.)
Possible Pitfalls and Ways to Avoid Them
o Starvation (edge-triggered)
If there is a large amount of I/O space, it is possible that by trying
to drain it the other files will not get processed causing starvation.
(This problem is not specific to epoll.)
The solution is to maintain a ready list and mark the file descriptor
as ready in its associated data structure, thereby allowing the appli-
cation to remember which files need to be processed but still round
robin amongst all the ready files. This also supports ignoring subse-
quent events you receive for file descriptors that are already ready.
o If using an event cache...
If you use an event cache or store all the file descriptors returned
from epoll_wait(2), then make sure to provide a way to mark its closure
dynamically (i.e., caused by a previous event’s processing). Suppose
you receive 100 events from epoll_wait(2), and in event #47 a condition
causes event #13 to be closed. If you remove the structure and
close(2) the file descriptor for event #13, then your event cache might
still say there are events waiting for that file descriptor causing
confusion.
One solution for this is to call, during the processing of event 47,
epoll_ctl(EPOLL_CTL_DEL) to delete file descriptor 13 and close(2),
then mark its associated data structure as removed and link it to a
cleanup list. If you find another event for file descriptor 13 in your
batch processing, you will discover the file descriptor had been previ-
ously removed and there will be no confusion.
VERSIONS
The epoll API was introduced in Linux kernel 2.5.44. Support was added
to glibc in version 2.3.2.
CONFORMING TO
The epoll API is Linux-specific. Some other systems provide similar
mechanisms, for example, FreeBSD has kqueue, and Solaris has /dev/poll.
SEE ALSO
epoll_create(2), epoll_create1(2), epoll_ctl(2), epoll_wait(2)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-02-01 EPOLL(7)