libevent 中应用程序驱动的事件
我想使用 libevent 来构建事件驱动应用程序的原型。具体来说,我想使用 PHP libevent 扩展。
我想知道的是以下内容。 libevent 似乎围绕打开文件处理程序/套接字/流事件展开。我希望能够抛出我自己的应用程序驱动事件来进行通信。
那么,如何使用文件句柄来传递自定义事件呢?这真的是要走的路吗?
I'd like to use libevent to prototype an event-driven application. Specifically, I want to use the PHP libevent extension.
What I'm wondering is the following. libevent seems to revolve around open file handler/socket/streams events. I'd like to be able to throw my own application-driven events for communication.
So, how would one use a file handle to pass around custom events? Is this really the way to go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案如下:
不需要以这种方式处理非基于 io 的事件,因为它们永远不会出现在事件循环中。
规则基本上是“所有基于 io 的事件都添加到循环中,所有其他事件立即执行”。
这确实给我留下了必须“伪造”事件的问题,或者只是稍微推迟执行。 libevent 确实提供了定时事件,并且有一个 PHP api,但它没有文档记录,我无法让它工作。
The solution for this is as follows..
There's no need to deal with non io-based events in this manner, as they will never have to end up in the event loop.
The rule is pretty much, "all io-based events are added to the loop, all other events are executed immediately".
This does leave me with the issue of having to 'fake' events, or simply have slightly deferred execution. libevent does provide timed events, and there is a PHP api for this but it's undocumented and I couldn't get it to work.