select函數本是被用作檢測系統文件描述符的狀態
int threadDelay(const int sec, const int usec){
timeval tv;
tv.tv_sec = sec;
tv.tv_usec = usec;
if (0 != select(0, NULL, NULL, NULL, &tv)){
return -1;
}
return 0;
}
其中第一個參數maxfd設置爲fd_set中最大文件描述符的值+1,因爲select實際上遍歷了到maxfd爲止的所有描述符是否可用,當其被設置爲0時就不檢測任何描述符
最後一個參數爲等待的時間,相當於收到一個信號量,函數從阻塞狀態返回