Select 函數

函數允許進程指示內核等待多個事件中的任何一個發生,並只在有一個或多個事件發生或經歷一段指定的時間後才喚醒它。


函數說明
#include<sys/select.h>
#include<sys/time.h>
int select(int maxfd, fd_set *readset, fd_set *writeset,
 fd_set *exceptset,const struct timeval *timeout);
              若有就緒描述符則爲其數目,若超時則爲0,若出錯則爲-1.

timeout 參數:
    1、設置爲空指針--永遠等下去,僅有一個描述符準備好I/O時才返回。
    2、設置timnout結構體的時間--等待一段固定的時間,在有一個描述符準備好I/O時返回,但是不能超時。
    注意:函數並不變timeout結構體的值,若是函數被中斷,並不返回剩餘的時間。
    3、timeout結構體設置爲0--不等待,檢查描述符後立即返回。

操作描述符集的函數
#include<sys/select.h>
int FD_SISET( int fd, fd_set *fdset);
               返回值:若是fd在描述符集中,返回非0值,否則,返回0
void FD_CLR(int fd, fd_set *fdset);
void FD_SET(int fd,fd_set *fdset);
void FD_ZERO(int fd,fd_set *fdset);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章