歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux epoll的使用

Linux epoll的使用

日期:2017/3/1 10:09:15   编辑:Linux編程

在Linux上,執行man epoll之後,可以得到這些結果

  1. NAME
  2. epoll - I/O event notification facility
  3. SYNOPSIS
  4. #include <sys/epoll.h>
  5. DESCRIPTION
  6. epoll is a variant of poll(2) that can be used either as Edge or Level Trig-
  7. gered interface and scales well to large numbers of watched fds. Three system
  8. calls are provided to set up and control an epoll set: epoll_create(2),
  9. epoll_ctl(2), epoll_wait(2).
  10. An epoll set is connected to a file descriptor created by epoll_create(2).
  11. Interest for certain file descriptors is then registered via epoll_ctl(2).
  12. Finally, the actual wait is started by epoll_wait(2).

epoll相關的的系統調用有:epoll_create, epoll_ctl和epoll_wait。

epoll_create用來創建一個epoll文件描述符。

epoll_ctl用來添加、修改、刪除需要偵聽的文件描述符及其事件。

epoll_wait/epoll_pwait 接收發生在被偵聽的描述符上的,用戶感興趣的IO事件。

這個條件符使用完之後,直接用close關閉即可。另外,任何被偵聽的文件描述拊只要其被關閉,那麼它也會自動的從被偵聽的文件描述符集體中刪除。

一,epoll_create

函數聲明如下: int epoll_create(int maxfds)

參數表示EPOLL所支持的最大句柄數,函數會返回一個新的EPOLL句柄,之後的所有操作將通過這個句柄來進行操作。該 函數生成一個epoll專用的文件描述符,會向內核申請一空間,用來存放你想存眷的socket fd上是否產生以及產生了什麼事務。

Copyright © Linux教程網 All Rights Reserved