重温“如何一起使用aio和epoll”
按照 的讨论您在单个事件循环中同时使用 AIO 和 epoll 吗?。
事实上,Linux 中有 2 个“aio”API。 有 POSIX aio(aio_* 系列函数),包含在我相信由 RedHat(?)开发的 glibc 和 libaio 中,io_* 系列。
第一个允许通过 aio_sigevent aiocb 成员注册通知请求。这可以轻松地与 ppoll()/pselect() 事件循环集成。如果你想将 POSIX aio 与 epoll() 集成,那么你需要将信号转换为虚拟 fd 上的事件(可能是管道)并使用 epoll 监听它,同时以经典方式或使用 ppoll/ 捕获信号选择。第一选择(普通的叹息者)的安全性取决于应用。也许在 epoll 上,但我不完全了解它的内部结构。我可以放心地假设,如果我有一个基于 epoll 的应用程序,并且我想添加 POSIX aio 支持,那么我就完蛋了?这是我的问题。
第二个 AIO 实现 libaio - 实际上可以与 eventfd() 一起使用(struct iocb 具有预计为零的 aio_resfd 成员或将 AIO 结果传递到的 eventfd)。但这不是书本上的。也就是说,POSIX 指定的。
我梦想自己成为一个一切都清晰的 *BSD 用户。您拥有对 AIO 事件的 POSIX AIO 和 kqueue() 支持。晶莹剔透。就像许多其他事情一样。
following the discussion at How do you use AIO and epoll together in a single event loop?.
There are in fact 2 "aio" APIs in linux.
There's POSIX aio (the aio_* family of functions), included in glibc and libaio developed I believe by RedHat (?), the io_* family.
The first one allows registration of notification requests via aio_sigevent aiocb member. That can be easily integrated with ppoll()/pselect() event loops. If you want to integrate POSIX aio with epoll() then you need to translate the signal into an event on a dummy fd (a pipe maybe) and listen for it with epoll, while catching the signal either in a classic manner or with ppoll/select. How safe is the first choice (normal sighandlers), depends on application. And maybe on epoll but i'm not fully aware of its internals. May I safely assume that if I have an epoll based app and I want to add POSIX aio support then I'm screwed? This was my question.
The second AIO implementation, libaio - can be used indeed with eventfd() (struct iocb having an aio_resfd member that is expected to be zero or an eventfd to deliver AIO results to). But it's not by the book. POSIX-specified, that is.
I dream of myself being a *BSD user where everything is clear. You have the POSIX AIO and kqueue() support for AIO events. Crystal clear. Like many other things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,您可以将 POSIX aio 与 epoll 一起使用,有
signalfd(2)
它创建一个文件描述符,然后您可以使用该文件描述符来接收基于 epoll 的循环中的信号通知。另外,第二个 aio API 应该最终是 glibc 实现 POSIX aio 的基础,它只是还没有完全实现......(我也不知道是否有人正在研究它)
note you CAN use POSIX aio with epoll, there's
signalfd(2)
it creates a file descriptor that you can then use to be notified of signals in an epoll based loop.Also the second aio API is supposed to eventually be what glibc bases it's implementation of POSIX aio on, it's just not quite there yet... (I don't know if anyone is working on it either)