11

关注如何在单个事件循环中同时使用 AIO 和 epoll?.

linux 中实际上有 2 个“aio”API。有 POSIX aio(aio_* 系列函数),包含在我相信由 RedHat(?)开发的 glibc 和 libaio 中,即 io_* 系列。

第一个允许通过 aio_sigevent aiocb 成员注册通知请求。这可以很容易地与 ppoll()/pselect() 事件循环集成。如果您想将 POSIX aio 与 epoll() 集成,那么您需要将信号转换为虚拟 fd(可能是管道)上的事件并使用 epoll 监听它,同时以经典方式或使用 ppoll/ 捕获信号选择。首选(普通 sighandlers)有多安全,取决于应用。也许在 epoll 上,但我并不完全了解它的内部结构。我可以安全地假设,如果我有一个基于 epoll 的应用程序并且我想添加 POSIX aio 支持,那么我就完蛋了?这是我的问题。

第二个 AIO 实现 libaio - 确实可以与 eventfd() 一起使用(结构 iocb 具有预期为零的 aio_resfd 成员或将 AIO 结果传递到的 eventfd)。但这不是书本上的。POSIX 指定的,即。

我梦想自己成为一个*BSD 用户,一切都很清楚。您拥有对 AIO 事件的 POSIX AIO 和 kqueue() 支持。晶莹剔透。像许多其他事情一样。

4

1 回答 1

6

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)

于 2010-10-22T15:37:25.173 回答