[英]How to wake up epoll_wait() before any event happened?
I have a Connection
object that represents a connection managed by epoll
. 我有一个
Connection
对象,它表示由epoll
管理的连接。 On events, the Connection::eventWrite()
or Connection::eventRead()
are invoked. 在事件上,将调用
Connection::eventWrite()
或Connection::eventRead()
。 Connection is persistent (exists always). 连接是持久的(始终存在)。
I need to send data via that Connection
from another thread, but don't want to access the object Connection
directly, because I dont want to solve multithreading issues inside the Connection
object ( Connection
is accessed from epoll
-thread and from "sending thread"). 我需要从另一个线程通过该
Connection
发送数据,但是不想直接访问对象Connection
,因为我不想解决Connection
对象内部的多线程问题( Connection
是从epoll
-thread和“发送线程”访问的) )。 Instead, I want to tell epoll
-thread: "wake up and do something with Connection
" -- epoll_wait()
should return and my code will find out that a CUSTOM EVENT
is occured (and, for example, some function should be called, where the desired access to Connection
will be performed (assign sending data to object, calling writeEvent()
), then epoll_wait()
-loop will be continued. 相反,我想告诉
epoll
-thread:“醒来并用Connection
做一些事情” epoll_wait()
应该返回,我的代码将发现发生了CUSTOM EVENT
(例如,应调用某些函数,在其中将执行对Connection
的所需访问(将数据发送给对象,调用writeEvent()
),然后epoll_wait()
将继续。
What kind of solutions exists for waking up a epoll_wait()
and which one is faster? 存在哪种唤醒
epoll_wait()
的解决方案,哪种解决方案更快? For now, I came up with creating a pipe
(handled by the same epoll
) and writing a byte 1
to it. 现在,我想到创建一个
pipe
(由相同的epoll
处理)并向其写入字节1
。 What else IPC exists which can be expressed via int
"epollable" file descriptor? 还可以通过
int
“ epollable”文件描述符表示什么IPC?
Epoll can wait on eventfd
. Epoll可以等待
eventfd
。 In your case, I'd create an eventfd
and than trigger this event. 就您而言,我将创建一个
eventfd
然后触发该事件。 I think, this is the cleanest solution. 我认为,这是最干净的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.