iocp
内核对象的概念,是什么?
设备内核对象?
事件内核对象?
An I/O completion port is associated with the process that created it and is not sharable between processes. However, a single handle is sharable between threads in the same process.
IOCP 相关的基础 API 只有这三个,相关类型和函数的描述:
1 | HANDLE WINAPI CreateIoCompletionPort( |
1 | BOOL GetQueuedCompletionStatus( |
1 | BOOL WINAPI PostQueuedCompletionStatus( |
1 | typedef struct _OVERLAPPED { |
Any unused members of this structure should always be initialized to zero before the structure is used in a function call.
其余三个属性一般置零 l.Offset = l.OffsetHigh = 0; l.hEvent = NULL;
The
WSAOVERLAPPED
structure is compatible with the WindowsOVERLAPPED
structure.
More
1 | BOOL ReadFile( |
The
WSAStartup
function initiates use of the Winsock DLL by a process.
The
WSAStartup
function must be the first Windows Sockets function called by an application or DLL.
By default, a socket created with the
WSASocket
function will not have this overlapped attribute set.
In contrast, thesocket
function creates a socket that supports overlapped I/O operations as the default behavior.
1 | int WSAAPI WSARecv( |
Overlapped IO 重叠输入输出
异步 I/O 技术(Overlapped I/O),避免使用多线程
激发的文件 handles / 设备内核对象
激发的 event 对象 / 事件内核对象
IOEvent 用的是 Overlapped IO 模型。使用起来也比较简单,仅需要将 fd buf overlapped(event) 这4者绑在一起,由内核完成数据的收发,并通过 event 通知应用层,应用层再进行数据操作已经完成后的操作,不需要多余的内存拷贝,数据已经在指定的 buf 上了。C++ SOCKET通信模型(二)IOEvent
异步过程调用 APCs(Asynchronous Procedure Calls)
I/O completion ports(重要)适用于高负载服务器
IOCP 输入输出完成端口
最后,我的建议是,想要使用 基于事件通知的 重叠 I/O 和基于完成例程的 重叠 I/O 的朋友,如果不是特别必要,就不要去使用了,因为这两种方式不仅使用和理解起来也不算简单,而且还有性能上的明显瓶颈