0

When I call WSASend() or WSARecv() or AcceptEx(), a completion packet will be placed in the completion port and I can dequeue it using GetQueuedCompletionStatus(). But how can I know what operation this completion packet represents?

  • 2
    Compare `LPOVERLAPPED` pointer you got from `GetQueuedCompletionStatus` with the pointer you passed to `WSASend` et al. You can also add additional members at the end of the structure, to stash extra information. – Igor Tandetnik Feb 24 '15 at 15:10
  • So I can add a `char` member to the end of the structure that will hold what type of operation this was, for example: 'S', 'R', 'A'? (this seems a better alternative than comparing pointers!) –  Feb 24 '15 at 18:29
  • @user4592590: yes, exactly. Raymond Chen described that feature on his blog: [The OVERLAPPED associated with asynchronous I/O is passed by address, and you can take advantage of that](http://blogs.msdn.com/b/oldnewthing/archive/2010/12/17/10106259.aspx) – Remy Lebeau Feb 24 '15 at 19:57

1 Answers1

2

You use an 'extended' OVERLAPPED structure which contains other information. Often this also contains the data buffer and some flags which tell the caller of GetQueuedCompletionStatus() what the completion type is.

There are lots of useful tutorials about IOCP on the web and I expect all of them explain this as it's fairly fundamental. My tutorials can be found here, along with some code which implements a some simple IOCP servers.

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