首页 > 其他 > 详细

select 函数小结 -- 转自百度知道

时间:2014-02-25 16:41:59      阅读:360      评论:0      收藏:0      [点我收藏+]
http://zhidao.baidu.com/link?url=UVTXeK4ncKmnwatGUW2deMFylNYBuur-zHmK3w53NXNRpgPbhld2WdkMD766nKl_6HjtW3t0tyB5kzFaQDHxha 

On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this. (POSIX.1-2001 permits either behavior.)
This causes problems both when Linux code which reads timeout is ported to other operating systems, and when code is ported to Linux that reuses a struct timeval
for multiple select()s in a loop without reinitializing it. Consider timeout to be undefined after select() returns.

linux在select调用之后会修改timeout值为无sleep的时间。所以第一次select是sleep了timeout设定的时间,然后timeout就被修改为0了(因为全部时间都在sleep,无sleep为0)。
在循环内调用第二次开始就有问题。

select 函数小结 -- 转自百度知道

原文:http://www.cnblogs.com/chenchenluo/p/3565580.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!