IO復用 poll系統呼叫

2021-10-02 06:22:20 字數 603 閱讀 9954

poll系統呼叫和select類似,也是在指定時間內輪詢一定數量的檔案描述符,以測試其中是否有已就緒的檔案描述符,pool原型如下:

#includeint poll(struct pollfd *fds,nfds_t nfds,int timeout);
1.fds引數是乙個pollfd結構型別的陣列,它指定所有我們感興趣的檔案描述符上發生的可讀、可寫和異常等事件,pollfd結構體的定義如下:

struct pollfd 

;

其中,fd成員指定檔案描述符,events告訴poll監聽fd上的哪些事件,它是一系列事件的按位或;revents成員由核心修改,以通知應用程式上fd實際發生了那些時間,poll支援的可關注的事件型別如下:

事件描述

pollin

資料可讀(包括普通資料和優先資料)

pollrdnorm

普通資料可讀

pollrdband

優先資料可讀(linux不支援)

pollpri

IO復用 poll函式

poll提供的功能與select函式類似,不過在處理流裝置時,它能夠提供額外的資訊 include int poll struct pollfd fdarray,unsigned long nfds,int timeout 返回 若有就緒的描述符則為其數目,若超時則為0,若出錯則為 1 第乙個引數是...

IO復用 poll函式

東陽的學習筆記 poll提供的功能和 select 類似,不過在處理流裝置時,它能提供額外的資訊。include intpoll struct pollfd fdarray,unsigned long nfds,int timeout 第乙個引數時指向乙個結構陣列第乙個元素的指標。每個陣列元素都是乙...

I O多路復用 poll

函式結構 int poll struct pollfd fds,nfds t nfds,int timeout 引數 返回值 和select一模一樣 events和revents events 關注事件 讀就緒 寫就緒 異常 輸入的時候起作用 revents 輸出結果,輸出的時候起作用 輸入輸出引數...