天天看點

epoll筆記

  1. int epoll_create(int size);

    creates a new epoll instance and

    returns a file descriptor referring to that instance

    建立一個新的epoll執行個體,并且傳回一個描述符指向這個執行個體

    參數:

    size,核心要監聽的數目

  2. int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);

    This system call performs control operations on the epoll(7) instance referred to by the file descriptor epfd.

    It requests that the operation op be performed for the target file descriptor, fd.

    (1)此系統調用對檔案描述符epfd所引用的epoll(7)執行個體執行控制操作。

    (2)它要求對fd執行op操作

op可選

EPOLL_CTL_ADD:把檔案描述符fd注冊到執行個體epfd上,并且将事件event與連結到fd的内部檔案關聯

EPOLL_CTL_MOD:更改與目标檔案描述符fd關聯的事件event。

EPOLL_CTL_DEL:從epfd引用的epoll執行個體中删除(登出)目标檔案描述符fd。事件被忽略,并且

The events member is a bit mask composed by ORing together zero or more of the following available event

types:

EPOLLIN

The associated file is available for read(2) operations.

EPOLLOUT

The associated file is available for write(2) operations.

事件成員是一個位掩碼,由以下零個或多個可用事件組成

類型:

EPOLLIN 相關檔案可以進行讀取操作

EPOLLOUT 相關檔案可以進行寫入操作

3.epoll_wait(2)

int epoll_wait(int epfd, struct epoll_event *events,int maxevents, int timeout);

waits for I/O events, blocking the calling thread if no events are currently available.

(1)等待I/O 事件,如果目前沒有擷取到事件的話,将阻塞調用線程

The memory area pointed to by events will contain the events that will be available for the caller.

參數:

<1> epfd:epoll執行個體

<2> event指向的記憶體區域将包含可供調用方使用的事件。

<3> maxevents 最大傳回數量

<4> 逾時時間timeout 指明了 epoll_wait 将阻塞的毫秒數,時間是由時鐘衡量

-1表示永久阻塞,0 立即傳回

繼續閱讀