poll() 超时为 0 时会做什么?
我正在查看 poll()
手册页,它告诉我当超时参数传入正值和负值时poll()
的行为。 它没有告诉我如果超时为 0
会发生什么。 有什么想法吗?
看看epoll_wait()
手册页,它告诉我,超时值为0
,即使没有可用的事件,它也会立即返回。 可以安全地假设 poll()
会有同样的行为吗?
I'm looking at the poll()
man page, and it tells me the behavior of poll()
when positive and negative values are passed in for the timeout parameter. It doesn't doesn't tell me what happens if timeout is 0
. Any ideas?
Looking at the epoll_wait()
man page, it tells me that with a timeout value of 0
, it will return right away, even if there are no events available. Is it safe to assume that poll()
would behave the same way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它将立即返回:
,从
Mac OS X 10.5
开始;,从
OpenBSD 3.8
开始It will return immediately:
, as of
Mac OS X 10.5
;, as of
OpenBSD 3.8
在我看来,等待超时意味着“拥有”超时。 这样,我希望 poll() 实际上检查文件描述符,然后如果没有人准备好,则等待 0 毫秒的超时(根本不等待)。 但是情况是,它只会发出信号,说明 fd 是否可用。
我还检查了linux源代码,据我所知,这是它的工作方式:首先计算“未来”等待点,然后检查文件描述符,如果没有可用的,则等待超时指定时间。
问候,
As I see it, waiting for a timeout means "having" a timeout. This way I would expect that poll() actually checks the file descriptors, and then waits if no one is ready to a timeout of 0 milliseconds (no wait at all). But the case is that it will just signal if a fd is available.
I also checked linux source code and to my knowledge, this is the way it works: first calculates the "future" waiting point, then checks the file descriptors, then if none available, waits for the timeout specified time.
Regards,
来自 Ubuntu 手册页:
因为 0 没有特殊情况,所以我假设 poll() 将阻塞 0 毫秒。
From the Ubuntu man pages:
Because there is no special case for 0, I would assume that poll() will block for 0 milliseconds.