1

I have iocp running and working (mostly) -- but should calling CloseHandle() on a handle cause it to complete?

e.g., I've called ReadFile() and it's now waiting for input to read. At another point I'm calling CloseHandle() from another thread in the pool used to service iocp completion packets. I expect for there to be a completion on the previous ReadFile() call with an ERROR_INVALID_HANDLE, but I'm not seeing that. Instead, it never seems to return. Could this be a sign that something else is holding a reference to the handle? If so, how would you suggest figuring that out/debugging it?

Any suggestions?

Thanks!

David Hoyt
  • 11
  • 2
  • Sure. You'll need to call CancelIo() on the handle before you close it. – Hans Passant Feb 15 '13 at 00:46
  • @HansPassant: note that `CancelIo()` only works when used in the same thread that started the IOCP operation that is begin canceled. If you want to cancel an IOCP operation that was started in another thread, you have to use `CancelIoEx()` instead. – Remy Lebeau Feb 15 '13 at 01:13
  • Yes, somebody is holding a reference to the handle: The `ReadFile` function itself! – Raymond Chen Feb 15 '13 at 02:52

0 Answers0