当 GetQueuedCompletionStatus() return FALSE 时,这些参数的值是多少?

What will be the values of these parameters when GetQueuedCompletionStatus() return FALSE?

有两个原因可以导致GetQueuedCompletionStatus()失败(return FALSE),第一个是因为在调用未完成时与其关联的完成端口句柄被关闭, 如果 lpOverlappedNULL.

就会出现这种情况

第二个原因(也是我比较关心的)是如果IO操作(例如:WSARecv())失败。这是文档对这种情况的描述:

If *lpOverlapped is not NULL and the function dequeues a completion packet for a failed I/O operation from the completion port, the function stores information about the failed operation in the variables pointed to by lpNumberOfBytes, lpCompletionKey, and lpOverlapped. To get extended error information, call GetLastError.

关于 lpNumberOfByteslpCompletionKeylpOverlapped 的值,我认为这不是很清楚。这些参数是否包含我在调用 WSARecv() 时提供的相同值?我想这更有可能是因为我还想知道是什么 IO 操作导致了失败!

如果 I/O 操作失败,则 lpCompletionKeylpOverlapped 将是您使用 API 启动 I/O 操作时提供的值使用了(WSASend()WSARecv() 等)。这就是您如何识别相关 I/O 操作的 'per device' 数据和 'per operation' 数据。

lpNumberOfBytes 在错误情况下可能为零,但我倾向于像处理非错误情况一样处理它,因为我在错误处理期间从不使用结果值(或缓冲区内容) .