在主动式 Web 服务器中接受连接的传统方式(使用异步 IO)
我目前正在 Linux 上探索 aio,以使用它来实现网络服务器。正如我已经发现的,没有太多资源详细介绍 aio 的用法。
问题是——在使用 aio 的单线程应用程序中接受客户端连接的传统方式是什么? (尽可能减少阻塞)
理想情况下,我可以看到 aio_accept 操作发送一个通知(在我的例子中是回调函数调用),表明连接已建立,并且 aio_read 在处理程序内立即被调用。但没有这样的电话:(
谢谢!
I'm currently exploring the aio on linux to use it for implementing a web-server. As I have already discovered, there are not too many resources that cover in detail the usage of aio.
The question is -- what is the conventional way of accepting the client connections in a single-threaded application that uses aio? (with minimum blocking possible)
Ideally, I can see aio_accept operation sending a notification (callback function call in my case) that the connection is established and the aio_read is called at once inside the handler. But there is no such call :(
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 aio 不适用于预接受套接字。
您可能想要选择它们,或者可能在 SIGIO 准备好时获取它。
[编辑]
具体来说,手册页说:“打开文件的设备必须允许查找操作。即,不可能在像终端这样的设备上使用任何 AIO 操作,其中 lseek
调用会导致错误。”
套接字不允许查找操作,因此即使是接受后套接字也会显得不走运。
I don't think aio works on pre-accept sockets.
You probably want to select on them, or perhaps get SIGIO when it is ready.
[edit]
Specifically the man page says: "The device on which the file is opened must allow the seek operation. I.e., it is not possible to use any of the AIO operations on devices like terminals where an lseek
call would lead to an error."
Sockets do not allow the seek operation, so even post-accept sockets would seem out of luck.