首先 这两个函数 有这样的对应关系:
BOOL WINAPI GetQueuedCompletionStatus( _In_ HANDLE CompletionPort, _Out_ LPDWORD lpNumberOfBytes, _Out_ PULONG_PTR lpCompletionKey, _Out_ LPOVERLAPPED *lpOverlapped, _In_ DWORD dwMilliseconds);BOOL WINAPI PostQueuedCompletionStatus( _In_ HANDLE CompletionPort, _In_ DWORD dwNumberOfBytesTransferred, _In_ ULONG_PTR dwCompletionKey, _In_opt_ LPOVERLAPPED lpOverlapped);
CompletionPort [in]A handle to an I/O completion port to which the I/O completion packet is to be posted.dwNumberOfBytesTransferred [in]The value to be returned through the lpNumberOfBytesTransferredparameter of the GetQueuedCompletionStatus function.dwCompletionKey [in]The value to be returned through the lpCompletionKey parameter of theGetQueuedCompletionStatus function.lpOverlapped [in, optional]The value to be returned through the lpOverlapped parameter of theGetQueuedCompletionStatus function.
此间主要有两个问题没有理清楚:
1.没有想明白 第三个参数 _In_ ULONG_PTR dwCompletionKey, 可以是自定义的数据类型, 例如int, 我的工程中传值为 iocp_api::Accept(=2), 即简单的 int 数值 值为 2, 那么在
BOOL WINAPI GetQueuedCompletionStatus( _In_ HANDLE CompletionPort, _Out_ LPDWORD lpNumberOfBytes, _Out_ PULONG_PTR lpCompletionKey, _Out_ LPOVERLAPPED *lpOverlapped, _In_ DWORD dwMilliseconds);
函数 的 _Out_ PULONG_PTR lpCompletionKey 的值就会是 2, 我的问题出在“进行普通的 GetQueuedCompletionStatus() 处理时, 参数是返回地址指针类型“ , 没有意识到 该指针的值 就是 0x00000002
2.没有注意到 两个函数的 微妙非堆成区别:
BOOL WINAPI GetQueuedCompletionStatus( ..., _Out_ LPOVERLAPPED *lpOverlapped, ... );
BOOL WINAPI PostQueuedCompletionStatus( ..., _In_opt_ LPOVERLAPPED lpOverlapped );
GetQueuedCompletionStatus() 要求的是 LPOVERLAPPED *
而 PostQueuedCompletionStatus() 是 LPOVERLAPPED
联系客服