epoll學習隨筆
阿新 • • 發佈:2021-06-18
int epoll_create(int size);// 建立epoll 例項 int epoll_ctl(int epfd,int op,int fd,struct epoll_event* event) //
op為列舉型別,可選擇的引數有
EPOLL_CTL_ADD // register the target descriptor fd on epoll instance EPOLL_CTL_MOD // change the event associated with the target file descriptor fd EPOLL_CTL_DEL // remove the target file descriptor fd from epoll instance
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_data_t data; };
常用的event types:
EPOLLIN // the associated file is available for read operations; EPOLLOUT // the associated file is available for write operations; EPOLLERR // error condition happened on the associated file desciptor EPOLLET // sets the edge triggered behavior for the associated file descriptor
epoll_wait 函式
int epoll_wait(int epfd,struct epoll_event *events,int maxevents,int timeout);
檢測新增到epoll樹上的節點是不是處於就緒狀態,如果沒有就緒的檔案描述符會阻塞
如果有節點處於就緒狀態,通過引數events 把對應的fd傳出。