为了账号安全,请及时绑定邮箱和手机立即绑定

请问关于select函数的操作程序?

请问关于select函数的操作程序?

红颜莎娜 2019-07-09 10:06:02
select函数的操作程序
查看完整描述

4 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

下面具体解释:
#include <sys/types.h>
#include <sys/times.h>
#include <sys/select.h>
int select(nfds, readfds, writefds, exceptfds, timeout)
int nfds;
fd_set *readfds, *writefds, *exceptfds;
struct timeval *timeout;
nfds:select监视的文件句柄数,视进程中打开的文件数而定,一般设为你要监视各文件
中的最大文件号加一。(注:nfds并非一定表示监视的文件句柄数。官方文档仅指出nfds is the highest-numbered file descriptor in any of the three sets, plus 1. (可在linux环境中通过man select命令查得))
readfds:select监视的可读文件句柄集合。
writefds: select监视的可写文件句柄集合。
exceptfds:select监视的异常文件句柄集合。
timeout:本次select()的超时结束时间。(见/usr/sys/select.h,可精确至百万分之一秒!)
当readfds或writefds中映象的文件可读或可写或超时,本次select()
就结束返回。程序员利用一组系统提供的宏在select()结束时便可判
断哪一文件可读或可写,对Socket编程特别有用的就是readfds。



查看完整回答
反对 回复 2019-07-14
  • 4 回答
  • 0 关注
  • 638 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信