#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);
最大で timeout ミリ秒間イベントを待つ。 timeout を -1 に指定すると、 epoll_wait() は無限に待つ。 また timeout を 0 に指定すると、 epoll_wait() はイベントが利用可能でなくても、すぐに返る (返り値は 0 である)。
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; /* ユーザデータ変数 */
};
返される構造体の data メンバには、ユーザが epoll_ctl(2) (EPOLL_CTL_ADD, EPOLL_CTL_MOD) で指定したデータが格納される。 一方、 events メンバには返された利用可能なイベントのビットフィールドが格納される。
以下の epoll_pwait() の呼び出しは、
ready = epoll_pwait(epfd, &events, maxevents, timeout, &sigmask);
次の呼び出しを
atomic
に実行するのと等価である。
sigset_t origmask;
sigprocmask(SIG_SETMASK, &sigmask, &origmask);
ready = epoll_wait(epfd, &events, maxevents, timeout);
sigprocmask(SIG_SETMASK, &origmask, NULL);
sigmask 引き数には NULL を指定してもよい。 その場合には、 epoll_pwait() は epoll_wait() と等価となる。
epoll_pwait() の glibc でのサポートは glibc 2.6 以降で提供されている。