資源和工具
基礎(chǔ)
x.1 select
int fs_sel;
fd_set fs_read;
struct timeval time;
FD_ZERO(&fs_read);//FD_ZERO(*set):將set初始化為空集NULL锌蓄。
FD_SET(fd, &fs_read);//FD_SET(s,*set):向集合添加描述字s账嚎。
time.tv_sec = 1;
time.tv_usec = 0;
// int select(
// int nfds ,
// fd_set* readfds ,
// fd_set* writefds ,
// fd_set* exceptfds ,
// const struct timeval* timeout
// );
// nfds:本參數(shù)忽略,僅起到兼容作用。
// readfds:(可選)指針逊笆,指向一組等待可讀性檢查的套接口罪治。
// writefds:(可選)指針图甜,指向一組等待可寫性檢查的套接口底靠。
// exceptfds:(可選)指針,指向一組等待錯(cuò)誤檢查的套接口呢蛤。
// timeout:select()最多等待時(shí)間惶傻,對(duì)阻塞操作則為NULL。
//wait 1 sec
//watch the fd_sets readable or writeable
fs_sel = select(fd + 1, &fs_read, NULL, NULL, &time);
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者