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

select函数的操作程序


红颜莎娜
浏览 644回答 4
4回答

RISEBY

下面具体解释:#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。
打开App,查看更多内容
随时随地看视频慕课网APP