views:

22

answers:

0

I'm currently working on an IPC mechanism based on named pipes using a IO completion port.

Unfortunately I have some troubles with the msdn documentation because it's quite unclear to me in which cases calls to ReadFile/WriteFile result in a completion packet.

The case when FALSE is returned with ERROR_IO_PENDING is clear, but what about the apparently possible case, when ERROR_MORE_DATA is returned? Will there be a completion packet in this case? Moreover, what if other errors are returned? In which cases do i have to handle the result and free resources directly and not in the completion handler?

Another case would be if ReadFile/WriteFile even succeed, which apparently is possible, too. MSDN is thankfully pretty clear about this here:

Further, the WriteFile function will sometimes return TRUE with a GetLastError value of ERROR_SUCCESS, even though it is using an asynchronous handle (which can also return FALSE with ERROR_IO_PENDING). ... In this example, the recommendation would be to allow the completion port routine to be solely responsible for all freeing operations for such resources.

Is this recommendation correct in all cases, and the result of an ReadFile/WriteFile operation for handles assigned to a completion port could (and should) in fact be ignored completely, because a packet is sent to the port anyways?