简体   繁体   English

epoll_wait:让它永远等待

[英]epoll_wait : making it wait for ever

As per to the man page of epoll_wait, following has been described.根据 epoll_wait 的手册页,已经描述了以下内容。

int epoll_wait(int epfd, struct epoll_event *events,
                      int maxevents, int timeout);

In kernels before 2.6.37, a timeout value larger than approximately LONG_MAX / HZ milliseconds is treated as -1 (ie, infinity).在 2.6.37 之前的内核中,大于大约 LONG_MAX / HZ 毫秒的超时值被视为 -1(即无穷大)。 Thus, for example, on a system where the sizeof(long) is 4 and the kernel HZ value is 1000, this means that timeouts greater than 35.79 minutes are treated as infinity.因此,例如,在 sizeof(long) 为 4 且 kernel HZ 值为 1000 的系统上,这意味着超过 35.79 分钟的超时被视为无穷大。

In this sense, how would I set the timeout to for-ever without any kernel or hardware dependencies?从这个意义上说,我如何将超时设置为永远没有任何 kernel 或硬件依赖项? would setting timeout to (-1) would result in such behavior?将超时设置为(-1)会导致这种行为吗?

Thank you.谢谢你。

As of man epoll_wait从 man epoll_wait 开始

Specifying a timeout of -1 causes epoll_wait() to block indefinitely, while specifying a timeout equal to zero cause epoll_wait() to return immediately, even if no events are available.指定超时 -1 会导致 epoll_wait() 无限期地阻塞,而指定等于零的超时会导致 epoll_wait() 立即返回,即使没有可用的事件也是如此。

If you want an indefinite wait, then -1 is the right answer (no matter which system).如果您想要无限期等待,那么 -1 是正确的答案(无论哪个系统)。 But if you want to wait (on kernels before 2.6.37 and sizeof(long) is 4) more than 35.79 minutes but less than infinity, then you would have to split the calls, because of the specified bug.但是,如果您想等待(在 2.6.37 之前的内核上并且 sizeof(long) 为 4)超过 35.79 分钟但小于无穷大,那么由于指定的错误,您将不得不拆分调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM