1.1 select
- 函数原型
int select( int nfds, fd_set *readset, fd_set *writeset, fd_set* exceptset, struct timeval *timeout );
- 头文件
select
位于:#include <sys/select.h>
struct timeval
位于:#include <sys/time.h>
- 返回值
返回对应位仍然为1的fd的总数。
- 参数
- nfds:第一个参数是:最大的文件描述符值+1;
- readset:可读描述符集合;
- writeset:可写描述符集合;
- exceptset:异常描述符;
- timeout:select 的监听时长,如果这短时间内所监听的 socket 没有事件发生。
1.2 fd_set
1.2.1 清空描述符集合
FD_ZERO(fd_set *)
1.2.2 向描述符集合添加指定描述符
FD_SET(int, fd_set *)
1.2.3 从描述符集合删除指定描述符
FD_CLR(int, fd_set *)
1.2.4 检测指定描述符是否在描述符集合中
FD_ISSET(int, fd_set *)
1.2.5 描述符最大数量
#define FD_SETSIZE 1024