版權所有 © 2014 tutorialspoint
epoll_wait - 等待 epoll 檔案描述符上的 I/O 事件
#include <sys/epoll.h> int epoll_wait(int epfd, struct epoll_event * events, int maxevents, int timeout);
int epoll_wait(int epfd, struct epoll_event * events, int maxevents, int timeout);
在epoll檔案描述符epfd上等待事件,最多等待timeout毫秒。events指向的記憶體區域將包含可供呼叫方使用的事件。epoll_wait(2)最多返回maxevents個事件。
maxevents引數必須大於零。將timeout指定為-1使epoll_wait(2)無限期等待,而將timeout指定為零使epoll_wait(2)即使沒有可用事件也立即返回(返回程式碼等於零)。
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 events */ epoll_data_t data; /* User data variable */ };
typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t;
struct epoll_event { __uint32_t events; /* Epoll events */ epoll_data_t data; /* User data variable */ };
每個返回結構的data將包含使用者使用epoll_ctl(2)(EPOLL_CTL_ADD,EPOLL_CTL_MOD)設定的相同資料,而events成員將包含返回的事件位欄位。
成功時,epoll_wait(2)返回準備進行請求的 I/O 的檔案描述符數量,如果在請求的timeout毫秒內沒有檔案描述符準備就緒,則返回零。發生錯誤時,epoll_wait(2)返回-1,並且errno被相應地設定。
epoll_wait(2)是 Linux 核心 2.5.44 中引入的新 API。該介面應在 Linux 核心 2.5.66 中最終確定。
epoll_create (2)
epoll_ctl (2)
廣告