winsock select
select
The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O.
int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout );
Parameters
- nfds
- [in] Ignored. The nfds parameter is included only for compatibility with Berkeley sockets. readfds
- [in, out] Optional pointer to a set of sockets to be checked for readability. writefds
- [in, out] Optional pointer to a set of sockets to be checked for writability. exceptfds
- [in, out] Optional pointer to a set of sockets to be checked for errors. timeout
- [in] Maximum time for select to wait, provided in the form of a TIMEVAL structure. Set the timeout parameter to null for blocking operations.
?
?
?
http://hi.baidu.com/ytmayer/blog/item/602698667aa09422aa184cfd.html中,有:
struct timeval* timeout是select的超時(shí)時(shí)間,這個(gè)參數(shù)至關(guān)重要,它可以使select處于三種狀態(tài)。
第一,若將NULL以形參傳入,即不傳入時(shí)間結(jié)構(gòu),就是將select置于阻塞狀態(tài),一定等到監(jiān)視文件描述符集合中某個(gè)文件描述符發(fā)生變化為止;第二,若將時(shí)間值設(shè)為0秒0毫秒,就變成一個(gè)純粹的非阻塞函數(shù),不管文件描述符是否有變化,都立刻返回繼續(xù)執(zhí)行,文件無變化返回0,有變化返回一個(gè)正值;第三,timeout的值大于0,這就是等待的超時(shí)時(shí)間,即select在timeout時(shí)間內(nèi)阻塞,超時(shí)時(shí)間之內(nèi)有事件到來就返回了,否則在超時(shí)后不管怎樣一定返回,返回值同上述。
轉(zhuǎn)載于:https://www.cnblogs.com/WeRtogether/archive/2009/10/12/1581516.html
總結(jié)
以上是生活随笔為你收集整理的winsock select的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Silverlight中文件的生成操作与
- 下一篇: 启用IIS的Gzip压缩 【转】