以定时阻塞模式读取
我如何使 read (或其他等效函数)在函数到达执行时的特定时间内处于阻塞模式
,或者换句话说,等待尝试读取的时间量
how can i make read (or other equivalent function) be in blocking mode for a specific time from the time that function reach execution
or in other words, to wait for an amount of time in which is trying to read
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
alarm
可能是一个简单情况下的可行选择select
< /a> (或类似)以指定超时调用并监视文件描述符的读取alarm
could be a viable option for simple casesselect
(or similar) call with a specified timeout and monitor the file descriptor for reading你的问题比较模糊,所以我只能猜测你的意思。我猜您想尝试“阅读”直到达到某个截止日期或超时。在这种情况下,只需将对 read 函数的调用放在 while 循环中,该循环会根据某个预先确定的截止日期检查当前时间,并在达到时退出循环......
Your question is fairly vague, so I can only assume what you mean. I guess you are wanting to attempt to 'read' until a certain deadline or timeout has been reached. In which case, just put the call to the read function inside a while loop which checks the current time against some pre-determined deadline and exits the loop when it has been reached....