4 回答

TA貢獻1856條經驗 獲得超5個贊
下面具體解釋:
#include <sys/types.h>
#include <sys/times.h>
#include <sys/select.h>
int select(nfds, readfds, writefds, exceptfds, timeout)
int nfds;
fd_set *readfds, *writefds, *exceptfds;
struct timeval *timeout;
nfds:select監視的文件句柄數,視進程中打開的文件數而定,一般設為你要監視各文件
中的最大文件號加一。(注:nfds并非一定表示監視的文件句柄數。官方文檔僅指出nfds is the highest-numbered file descriptor in any of the three sets, plus 1. (可在linux環境中通過man select命令查得))
readfds:select監視的可讀文件句柄集合。
writefds: select監視的可寫文件句柄集合。
exceptfds:select監視的異常文件句柄集合。
timeout:本次select()的超時結束時間。(見/usr/sys/select.h,可精確至百萬分之一秒!)
當readfds或writefds中映象的文件可讀或可寫或超時,本次select()
就結束返回。程序員利用一組系統提供的宏在select()結束時便可判
斷哪一文件可讀或可寫,對Socket編程特別有用的就是readfds。
- 4 回答
- 0 關注
- 707 瀏覽
添加回答
舉報