以定时阻塞模式读取

发布于 2024-10-09 15:14:41 字数 73 浏览 0 评论 0原文

我如何使 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷不放纵 2024-10-16 15:14:41
  • Maybe alarm could be a viable option for simple cases
  • A probably better solution would involve blocking on a select (or similar) call with a specified timeout and monitor the file descriptor for reading
傾城如夢未必闌珊 2024-10-16 15:14:41

你的问题比较模糊,所以我只能猜测你的意思。我猜您想尝试“阅读”直到达到某个截止日期或超时。在这种情况下,只需将对 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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文