epoll_wait() - Unix,Linux 系統呼叫 - 技術教學
Tutorials Point


  Unix 初學者指南
  Unix Shell 程式設計
  高階 Unix
  Unix 有用參考
  Unix 有用資源
  精選閱讀

版權所有 © 2014 tutorialspoint



  首頁     參考     討論論壇     關於 TP  

epoll_wait() - Unix,Linux 系統呼叫


previous next AddThis Social Bookmark Button

廣告

名稱

epoll_wait - 等待 epoll 檔案描述符上的 I/O 事件

語法

#include <sys/epoll.h> 

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 */ };

每個返回結構的data將包含使用者使用epoll_ctl(2)(EPOLL_CTL_ADD,EPOLL_CTL_MOD)設定的相同資料,而events成員將包含返回的事件位欄位。

返回值

成功時,epoll_wait(2)返回準備進行請求的 I/O 的檔案描述符數量,如果在請求的timeout毫秒內沒有檔案描述符準備就緒,則返回零。發生錯誤時,epoll_wait(2)返回-1,並且errno被相應地設定。

錯誤

標籤描述
EBADF epfd不是有效的檔案描述符。
EFAULT events指向的記憶體區域無法使用寫許可權訪問。
EINTR 在任何請求的事件發生或timeout過期之前,呼叫被訊號處理程式中斷。
EINVAL epfd不是epoll檔案描述符,或者maxevents小於或等於零。

符合標準

epoll_wait(2)是 Linux 核心 2.5.44 中引入的新 API。該介面應在 Linux 核心 2.5.66 中最終確定。

參見



previous next Printer Friendly

廣告


  

廣告



廣告
© . All rights reserved.