Linux的I/O多路转接模型:
在这种模型下,如果请求的I/O操作阻塞,它不是真正阻塞I/O,而是让其中一个函数等待,在这期间,I/O还能进行其他操作。select()和poll()就属于这种模型。
select()函数说明
头文件#include<sys/types.h>
#include<sys/time.h>
#include<unistd.h>
原型 int select(int numfds,fd_set *readfds,fd_set *writefds,fd_set *exeptfds,struct timeval *timeout 参数numfds:需要检查的号码最高的文件描述符+1
readfds:由select()监视的读文件描述符集合
writefds:由select()监视的写文件描述符集合
exeptfds:由select()监视的异常处理文件描述符集合
timeout:
--- NULL:永远等待,直到捕捉到信号或文件描述符已经准备好为止
---具体值:struct timeval的指针,若timeout时间还没准备好,则立即返回
---0 :从不等待,测试所有指定的描述符并立即返回
返回值成功:准备好的文件描述符
-1:出错
对文件描述符操作的四个宏:
此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/59281.html