GetQueuedCompletionStatusEx() doesn't return a per-OVERLAPPED error code

c, c++, iocp, winapi, windows

Solution

The completion status is stored in the `OVERLAPPED.Internal` field. But as you noted, that's the native api status code, not a winapi error code. An easy way to translate it is to call GetOverlappedResult(). It doesn't matter what you pass for the bWait argument, it will always return immediately. Use WSAGetOverlappedResult() for sockets.

Problem

I'm using the `GetQueuedCompletionStatusEx()` api, and I've just realized that it can indeed read N OVERLAPPEDs packets in just 1 syscall, instead of only 1 OVERLAPPED, like `GetQueuedCompletionStatus()`, but my concern is that I cannot know anything about per-OVERLAPPED error code. While `GetQueuedCompletionStatus()` returns only 1 OVERLAPPED per call, it gives to me the ability to check, calling `GetLastError()`, the last error for the current OVERLAPPED packet. How I could do this with `GetQueuedCompletionStatusEx()` which in fact returns N OVERLAPPEDs packets, but not N error codes? I have read around that by calling `GetOverlappedResult()` you can achieve that, but my point is: if I call `GetQueuedCompletionStatusEx()` to get N OVERLAPPEDs packets, and then I have to call another syscall for EACH of them, the benefit of calling 1 syscall to get N OVERLAPPEDs is pointless, since you'll call 1+N syscalls. At this point I could stay simply with `GetQueuedCompletionStatus()` and call only N syscalls (for N OVERLAPPEDs) instead of 1+N. Do anyone know more about this?

Original source