
110
|
第四章
event.data.fd = fd; /* 稍後把 fd 傳回給我們 */
event.events = EPOLLIN;
ret = epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &event);
if (ret)
perror ("epoll_ctl");
反過來說,欲從「epoll 實例」
epfd
中移除特定檔案(相應於
fd
)上一個既存的事件檢
視器,可以這麼做:
struct epoll_event event;
int ret;
ret = epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &event);
if (ret)
perror ("epoll_ctl");
注意,當
op
的值為
EPOLL_CTL_DEL
時,
event
參數可以是
NULL
,因為沒有提供事件遮
罩(event mask)。然而,核心版本在 2.6.9 之前,會錯誤地檢查此參數是否為「非
NULL」值。若要移植到這些版本較舊的核心,你應該傳進一個有效的「非 NULL」指
標;它將不會被觸動。核心版本 2.6.9 已修正此瑕疵。
以 epoll 等待事件
系統呼叫
epoll_wait()
用於等待「與特定 epoll 實例相對應之檔案描述器」上的事件:
#include <sys/epoll.h>
int epoll_wait (int epfd,
struct epoll_event *events,
int maxevents,
int timeout);
叫用
epoll_wait() ...