Man page - epoll_wait(2)

Packages contains this manual

Available languages:

en fr ja ru ro

Manual

EPOLL_WAIT

名 前
書 式
説 明
epoll_pwait()
返 り 値
エ ラ ー
バ ー ジ ョ ン
準 拠
注 意
バ グ
C ラ イ ブ ラ リ と カ ー ネ ル の 違 い
関 連 項 目
こ の 文 書 に つ い て

名 前

epoll_wait, epoll_pwait - epoll フ ァ イ ル デ ィ ス ク リ プ タ ー の I/O イ ベ ン ト を 待 つ

書 式

#include <sys/epoll.h>

int epoll_wait(int epfd , struct epoll_event * events ,
int
maxevents , int timeout );
int epoll_pwait(int
epfd , struct epoll_event * events ,
int
maxevents , int timeout ,
const sigset_t *
sigmask );

説 明

The epoll_wait () system call waits for events on the epoll (7) instance referred to by the file descriptor epfd . The buffer pointed to by events is used to return information from the ready list about file descriptors in the interest list that have some events available. Up to maxevents are returned by epoll_wait (). The maxevents argument must be greater than zero.

The timeout argument specifies the number of milliseconds that epoll_wait () will block. Time is measured against the CLOCK_MONOTONIC clock.

A call to epoll_wait () will block until either:

フ ァ イ ル デ ィ ス ク リ プ タ ー が イ ベ ン ト を 配 送 し た

呼 び 出 し が シ グ ナ ル ハ ン ド ラ ー に よ り 割 り 込 ま れ た

タ イ ム ア ウ ト が 満 了 す る

timeout 時 間 は シ ス テ ム ク ロ ッ ク の 粒 度 に 切 り 上 げ ら れ 、 カ ー ネ ル の ス ケ ジ ュ ー リ ン グ 遅 延 に よ り 少 し だ け 長 く な る 可 能 性 が あ る 点 に 注 意 す る こ と 。 timeout を -1 に 指 定 す る と 、 epoll_wait () は 無 限 に 停 止 す る 。 timeout を 0 に 指 定 す る と 、 epoll_wait () は 利 用 可 能 な イ ベ ン ト が な く て も 、 す ぐ に 返 る 。

struct epoll_event は 以 下 の よ う に 定 義 さ れ る 。

typedef union epoll_data {
void *ptr;
int fd;
uint32_t u32;
uint64_t u64;
} epoll_data_t;

struct epoll_event {
uint32_t events; /* epoll イ ベ ン ト */
epoll_data_t data; /* ユ ー ザ ー デ ー タ 変 数 */
};

The data field of each returned epoll_event structure contains the same data as was specified in the most recent call to epoll_ctl (2) ( EPOLL_CTL_ADD , EPOLL_CTL_MOD ) for the corresponding open file descriptor.

The events field is a bit mask that indicates the events that have occurred for the corresponding open file description. See epoll_ctl (2) for a list of the bits that may appear in this mask.

epoll_pwait()

epoll_wait () と epoll_pwait () の 関 係 は 、 select (2) と pselect (2) の 関 係 と 同 様 で あ る 。 pselect (2) 同 様 、 epoll_pwait () を 使 う と 、 ア プ リ ケ ー シ ョ ン は 、 フ ァ イ ル デ ィ ス ク リ プ タ ー が 準 備 で き た 状 態 に な る か 、 シ グ ナ ル が 捕 捉 さ れ る ま で 、 安 全 に 待 つ こ と が で き る 。

以 下 の epoll_pwait () の 呼 び 出 し は 、

ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);

次 の 呼 び 出 し を atomic に 実 行 す る の と 等 価 で あ る 。

sigset_t origmask;

pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
ready = epoll_wait(epfd, &events, maxevents, timeout);
pthread_sigmask(SIG_SETMASK, &origmask, NULL);

sigmask 引 数 に は NULL を 指 定 し て も よ い 。 そ の 場 合 に は 、 epoll_pwait () は epoll_wait () と 等 価 と な る 。

返 り 値

成 功 し た 場 合 、 epoll_wait () は 要 求 さ れ た I/O に 対 し て 準 備 が で き て い る フ ァ イ ル デ ィ ス ク リ プ タ ー の 数 を 返 す 。 ま た 要 求 さ れ た timeout ミ リ 秒 の 間 に フ ァ イ ル デ ィ ス ク リ プ タ ー が 準 備 で き な い 場 合 は 、 0 を 返 す 。 エ ラ ー が 起 こ っ た 場 合 、 epoll_wait () は -1 を 返 し 、 errno を 適 切 に 設 定 す る 。

エ ラ ー

EBADF

epfd が 有 効 な フ ァ イ ル デ ィ ス ク リ プ タ ー で な い 。

EFAULT

events で 指 さ れ る メ モ リ ー 領 域 に 書 き 込 み 権 限 で ア ク セ ス で き な い 。

EINTR

(1) 要 求 さ れ た ど の イ ベ ン ト も 発 生 せ ず 、 か つ (2) timeout の 期 限 が 切 れ る 前 に 、 シ ス テ ム コ ー ル が シ グ ナ ル ハ ン ド ラ ー に よ っ て 割 り 込 ま れ た 。 signal (7) 参 照 。

EINVAL

epfd epoll フ ァ イ ル デ ィ ス ク リ プ タ ー で な い 。 ま た は maxevents が 0 以 下 で あ る 。

バ ー ジ ョ ン

epoll_wait () は カ ー ネ ル 2.6 で 追 加 さ れ た 。 ラ イ ブ ラ リ に よ る サ ポ ー ト は glibc バ ー ジ ョ ン 2.3.2 以 降 で 提 供 さ れ て い る 。

epoll_pwait () は カ ー ネ ル 2.6.19 で Linux に 追 加 さ れ た 。 ラ イ ブ ラ リ に よ る サ ポ ー ト は glibc バ ー ジ ョ ン 2.6 以 降 で 提 供 さ れ て い る 。

準 拠

epoll_wait () は Linux 独 自 で あ る 。

注 意

あ る ス レ ッ ド が epoll_wait () を 呼 び 出 し て 停 止 さ れ て い る 間 に 、 別 の ス レ ッ ド が wait 中 の epoll イ ン ス ト ー ル に フ ァ イ ル デ ィ ス ク リ プ タ ー を 追 加 す る こ と が あ る 。 新 し い フ ァ イ ル デ ィ ス ク リ プ タ ー で イ ベ ン ト が 発 生 す る と 、 epoll_wait () の 呼 び 出 し に よ る 停 止 が 解 除 さ れ る こ と に な る 。

If more than maxevents file descriptors are ready when epoll_wait () is called, then successive epoll_wait () calls will round robin through the set of ready file descriptors. This behavior helps avoid starvation scenarios, where a process fails to notice that additional file descriptors are ready because it focuses on a set of file descriptors that are already known to be ready.

Note that it is possible to call epoll_wait () on an epoll instance whose interest list is currently empty (or whose interest list becomes empty because file descriptors are closed or removed from the interest in another thread). The call will block until some file descriptor is later added to the interest list (in another thread) and that file descriptor becomes ready.

バ グ

バ ー ジ ョ ン 2.6.37 よ り 前 の カ ー ネ ル で は 、 お お よ そ LONG_MAX / HZ ミ リ 秒 よ り 大 き い timeout 値 は -1 (つ ま り 無 限 大 ) と し て 扱 わ れ る 。 し た が っ て 、 例 え ば 、 sizeof(long) が 4 で 、 カ ー ネ ル の HZ の 値 が 1000 の シ ス テ ム で は 、 35.79 分 よ り も 大 き な タ イ ム ア ウ ト は 無 限 大 と し て 扱 わ れ る と い う こ と で あ る 。

C ラ イ ブ ラ リ と カ ー ネ ル の 違 い

素 の epoll_pwait () シ ス テ ム コ ー ル は 6 番 目 の 引 数 size_t sigsetsize を 取 る 。 こ の 引 数 は sigmask 引 数 の バ イ ト 単 位 の サ イ ズ を 指 定 す る 。 glibc の epoll_pwait () ラ ッ パ ー 関 数 は 、 こ の 引 数 に 固 定 値 ( sizeof(sigset_t) と 同 じ ) を 指 定 す る 。

関 連 項 目

epoll_create (2), epoll_ctl (2), epoll (7)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。