int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
分析:
- nfds: 监控的文件描述符集里最大文件描述符加1,因为此参数会告诉内核检测前多少个文件描述符的状态
- readfds: 监控有读数据到达文件描述符集合,传入传出参数
- writefds: 监控写数据到达文件描述符集合,传入传出参数
- exceptfds:监控异常发生达文件描述符集合,如带外数据到达异常,传入传出参数
- timeout: 定时阻塞监控时间
void FD_CLR(int fd, fd_set *set); //把文件描述符集合里fd清0
int FD_ISSET(int fd, fd_set *set); //测试文件描述符集合里fd是否置1
void FD_SET(int fd, fd_set *set); //把文件描述符集合里fd位置1
void FD_ZERO(fd_set *set); //把文件描述符集合里所有位清0
本文详细解析了select函数的使用方法及参数含义,包括nfds、readfds、writefds、exceptfds和timeout等,并介绍了FD_CLR、FD_ISSET、FD_SET、FD_ZERO四个辅助函数的作用。
384

被折叠的 条评论
为什么被折叠?



