函数允许进程指示内核等待多个事件中的任何一个发生,并只在有一个或多个事件发生或经历一段指定的时间后才唤醒它。
函数说明
#include<sys/select.h>
#include<sys/time.h>
int select(int maxfd, fd_set *readset, fd_set *writeset,
fd_set *exceptset,const struct timeval *timeout);
若有就绪描述符则为其数目,若超时则为0,若出错则为-1.
timeout 参数:
1、设置为空指针--永远等下去,仅有一个描述符准备好I/O时才返回。
2、设置timnout结构体的时间--等待一段固定的时间,在有一个描述符准备好I/O时返回,但是不能超时。
注意:函数并不变timeout结构体的值,若是函数被中断,并不返回剩余的时间。
3、timeout结构体设置为0--不等待,检查描述符后立即返回。
操作描述符集的函数
#include<sys/select.h>
int FD_SISET( int fd, fd_set *fdset);
返回值:若是fd在描述符集中,返回非0值,否则,返回0
void FD_CLR(int fd, fd_set *fdset);
void FD_SET(int fd,fd_set *fdset);
void FD_ZERO(int fd,fd_set *fdset);