服务器select函数的用法及原理 服务器select函数的用法及原理
发布时间
阅读量:
阅读量
Linux系统中,提供了三种可供使用的IO多路复用函数,其中select函数在网络通信编程中被广泛采用。该函数的主要作用是用于判断一组socket中是否存在事件已就绪的情况。
select的声明:
#include <sys/time.h> //for struct timeval
#include <unistd.h> //for select
/** * return 状态变化的文件描述符的个数
* @param nfds: linux上的socket也是一种fd(文件描述符),将这个参数的值设置为所有需要使用select函数检测事件的fd的最大值加1
* @param readfds:需要监听可读事件的fd集合
* @param writefds:需要监听可写事件的fd集合
* @param exceptfds: 需要监听的异常事件的fd集合
* @param timeout:超时时间,即在这个参数设定的时间内检测这些fd的事件,超过这个时间后,select函数立即返回。
**/
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, struct timeval
全部评论 (0)
还没有任何评论哟~
