Linux和I / O完成端口? [英] Linux and I/O completion ports?

查看:177
本文介绍了Linux和I / O完成端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用winsock,你可以配置插座或单独的I / O操作为重叠。这意味着,调用执行I / O都立即返回,而实际操作是由独立的工作线程异步完成。

Using winsock, you can configure sockets or seperate I/O operations to "overlap". This means that calls to perform I/O are returned immediately, while the actual operations are completed asynchronously by separate worker threads.

的Winsock还提供了完成端口。从我的理解,完成端口充当手柄(插座)的多路复用器。如果不是在I / O操作中的句柄可以解复用,即,如果它的所有I / O操作的已完成

Winsock also provides "completion ports". From what I understand, a completion port acts as a multiplexer of handles (sockets). A handle can be demultiplexed if it isn't in the middle of an I/O operation, i.e. if all its I/O operations are completed.

所以,关于我的问题... Linux支持完成端口,甚至异步I / O套接字?

So, on to my question... does linux support completion ports or even asynchronous I/O for sockets?

推荐答案

如果您正在寻找的东西完全一样IOCP,你不会找到它,因为它不存在。

If you're looking for something exactly like IOCP, you won't find it, because it doesn't exist.

Windows使用在完成模型通知(因此I / O的完成的端口)。你异步启动一些操作,并收到通知时操作已完成。

Windows uses a notify on completion model (hence I/O Completion Ports). You start some operation asynchronously, and receive a notification when that operation has completed.

Linux应用程序(和大多数其他Unix相似者)一般采用现成模型通知。您会收到插座可以读取或不阻塞写入通知。然后,你做的I / O操作,而不会阻塞。

Linux applications (and most other Unix-alikes) generally use a notify on ready model. You receive a notification that the socket can be read from or written to without blocking. Then, you do the I/O operation, which will not block.

在这种模式下,你不这样做的需求的异步I / O。该数据会立即复制到/出插槽缓冲区。

With this model, you don't need asynchronous I/O. The data is immediately copied into / out of the socket buffer.

该编程模型是一种棘手的,这就是为什么有喜欢的libevent抽象库。它提供了一个更简单的编程模型,抽象了支持的操作系统之间实现差异。

The programming model for this is kind of tricky, which is why there are abstraction libraries like libevent. It provides a simpler programming model, and abstracts away the implementation differences between the supported operating systems.

有是在Windows上的通知准备模型以及(选择或WSAWaitForMultipleEvents),你可能已经看过了。它不能扩展到大量的插座,所以它不适合高性能的网络应用。

There is a notify on ready model in Windows as well (select or WSAWaitForMultipleEvents), which you may have looked at before. It can't scale to large numbers of sockets, so it's not suitable for high-performance network applications.

不要让这把你赶走 - Windows和Linux是完全不同的操作系统。一些不顺利的一个系统规模可能在其他工作得很好。这种做法实际上工作得非常好于Linux,Windows上的表现堪比IOCP。

Don't let that put you off - Windows and Linux are completely different operating systems. Something that doesn't scale well on one system may work very well on the other. This approach actually works very well on Linux, with performance comparable to IOCP on Windows.

这篇关于Linux和I / O完成端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆