网络编程12 select多路复用

最后都变了- 提交于 2019-12-12 12:37:14

int select(int maxfd, fd_set *readset, fd_set *writeset, fd_set *exceptset, const struct timeval *timeout);
返回:若有就绪描述符则为其数目,若超时则为0,若出错则为-1

maxfd 表示的是待测试的描述符基数,它的值是待测试的最大描述符加 1。


void FD_ZERO(fd_set *fdset);      
void FD_SET(int fd, fd_set *fdset);  
void FD_CLR(int fd, fd_set *fdset);   
int  FD_ISSET(int fd, fd_set *fdset);

struct timeval {
  long   tv_sec; /* seconds */
  long   tv_usec; /* microseconds */
};

1、将timeval置为空,表示如果没有IO事件发生就将一直等待下去
2、表示一段固定的时间后,select从阻塞调用中返回
3、将tv_sec和tv_usec都置为0,表示不等待,立即返回

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!