POSIX AIO:有什么(好的)方法可以将完成通知与原始请求关联起来?
我是否正确地认为 AIO 完成通知(无论是通过线程还是信号完成)不会向您提供有关哪个请求已完成的信息?除了为每个请求调用单独的回调函数之外,还有什么方法可以实现这种关联吗?表面上,您可以使用原始请求的 aiocb 结构来调用 aio_error 和 aio_return,但您不会在通知回调中获得返回到 aiocb 结构的指针。为什么似乎没有机制可以做到这一点?
Am I right in thinking that AIO completion notifications (whether done via threads or signals) give you no information as to which request has completed? Is there any way to accomplish this correlation other than having separate callback functions called for each request? Ostensibly you can use the original request's aiocb structure to make calls to aio_error and aio_return, but you don't get a pointer back to the aiocb structure as part of the notification callback. Why does there seem to be no mechanism to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您提交
struct aiocb
来启动异步IO时,您可以使用struct sigevent
结构填充其aio_sigevent
成员:使用< code>aio_sigevent.sigev_value.sival_ptr 您可以存储指向您的
struct aiocb
(或具有您的struct aiocb
作为成员),然后您可以在调用信号处理程序时查找:aio(7)
手册页 在研究这个问题时非常有帮助,sigevent(7)
手册页包含详细信息在结构上sigevent
结构。When you submit a
struct aiocb
to initiate the asynchronous IO, you're allowed to populate itsaio_sigevent
member with astruct sigevent
structure:Using
aio_sigevent.sigev_value.sival_ptr
you can store a pointer to yourstruct aiocb
(or another structure that has yourstruct aiocb
as a member) which you can then look up when your signal handler is called:The
aio(7)
manpage was extremely helpful when researching this and thesigevent(7)
manpage has details on thestruct sigevent
structure.