1

If FILE_SKIP_COMPLETION_PORT_ON_SUCCESS is not enabled, then even if the operation completes immediately with success, I still get a completion notification on the completion port. I'd like to know if this is the case if it completes immediately with errors as well.

I process completions with handlers that I store as std::function in an extended OVERLAPPED struct, and are executed by the thread pool that is looping on the completion port. Having FILE_SKIP_COMPLETION_PORT_ON_SUCCESS disabled means that I don't have to worry about handlers forming a recursive chain and, worst case, running out of stack space, if the operations often complete immediately. With the skip enabled, the handler for the new operation would have to be called immediately if the operation returns right away.

The issue is that the handlers are supposed to execute both on success and on error. However, I don't know whether if an overlapped Read/Write/WSARecv/WSASend returning immediately with an error would still queue a completion packet, so that I can allow it to be handled in the handler by the thread pool, as in the case of success. Is this doable? Is it something that only applies to certain types of errors and not others? Workarounds?

Display Name
  • 2,323
  • 1
  • 26
  • 45
  • 1
    If you get an error and it is not ERROR_IO_PENDING then, no, the operation never got started so can't complete. – Hans Passant Aug 16 '14 at 09:11
  • I'm not certain, but I think Hans is right. (I hope so; otherwise, since some failure modes preclude queuing a completion packet, you'd never know whether you were going to get one or not.) However, you can always deal with this case by posting a completion packet yourself if that is appropriate. – Harry Johnston Aug 17 '14 at 00:42

2 Answers2

2

This knowledge base article says that SUCCESS and ERROR_IO_PENDING result in a completion packet being generated and other results do not.

See Tip 4

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
1

Based on this blog from Raymond Chen, all completions will be queued to the completion port even if the operation completes synchronously (successfully or with an error condition).

William
  • 1,867
  • 11
  • 10
  • Raymond was discussing the case where the I/O succeeds, I don't believe you can conclude that this is also true when the I/O fails. And there are obviously failure modes that preclude notification, e.g., if the handle was invalid. – Harry Johnston Aug 17 '14 at 00:37