中断epoll_wait用非IO事件,无信号 [英] Interrupting epoll_wait with a non-IO event, no signals

查看:255
本文介绍了中断epoll_wait用非IO事件,无信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前的情况是epoll_wait了一对夫妇FDS和可能收到的消息队列,我想下面epoll_wait环路要在IO事件或对新的消息执行。结果
方法我知道:

Current scenario is epoll_wait over a couple of fds and a queue of possible incoming messages, I'd like the loop below epoll_wait to be executed on IO event or on new message.
Ways I know:


  • 使用一个时间毫秒超时,并检查队列第一件事就是循环

  • 从队列code使用自管招的消息时,可用

  • 与标准信号中断的系统调用

  • 使用epoll_pwait和细化previous点

  • Use a time msec timeout and check the queue first thing in the loop
  • Use the self-pipe trick from the queue code when messages become available
  • Interrupt the syscall with a standard signal
  • Use epoll_pwait and refine the previous point

之分,没有上面贴满足了我足够的,如果有,我还没有发现任何其他方法我想知道。结果
理由是:

None of the points posted above satisfy me enough and I was wondering if there are any other methods that I haven't found.
Reasons are:


  • 的信号是什么,以避免对多线程code和是不是非常可靠

  • 超时1删除的epoll的利益的一部分,只有事件醒来

  • 自管招查找目前最好的办法,但仍然太多样板

想法?

推荐答案

您可以使用的 eventfd 这实际上是同样的事情,只是用较少的文件描述符和更少的样板(自管招的glibc具有方便 eventfd_read /写比如函数)。

You can use an eventfd which is effectively the same thing as the self-pipe trick except with fewer file descriptors and less boilerplate (glibc has convenience eventfd_read/write functions for instance).

这篇关于中断epoll_wait用非IO事件,无信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆