0

In IOCP, when starting an IO operation such as WSARecv(), a completion packet will be sent to the completion port when the IO operation completes.

What I want to know is what IO operations causes completion packets to be sent to the completion port when using sockets, for example, I know that WSASend(), WSARecv(), AcceptEx(), and PostQueuedCompletionStatus() causes completion packets to be sent. Is there other IO operations that does that?

3 Answers3

3

A completion will be queued to the IOCP associated with a socket only if an API call that can generate completions is called in a way that requests a completion to be queued. So you will know which API calls can generate completions by the fact that you've read the documentation and you're passing an OVERLAPPED structure to them.

Thus you don't really need to know the answer to your question as you will never get a completion that you do not expect to get as you have to have called an appropriate API with appropriate parameters for a completion to be generated.

You can then differentiate between the API that caused the completion to be generated by adding some form of identifying "per operation data" to the OVERLAPPED either by making an 'extended overlapped stucture' or by using the event handle as opaque data. Either way you get a chance to send some context from the API call site to the IOCP completion handling site. This context is of your own design and can tell you what initiated the completion.

Then you get to use the return value from the GetQueuedCompletionStatus() call to determine if the completion is a success or failure and you can then access the error code for failures using WSAGetLastError() (though see this answer for more detail on an additional hoop that you could jump through to get more accurate error codes).

This then lets you determine which of the events listed in EJP's answer you have.

The actual set of functions that can generate a completion for socket operations can change with changes in the OS. The easiest way to determine what these are for the operating system that you're targeting is to either read the MSDN docs or do a search of the SDK headers for lpOverlapped... As you'll see from the current VS2013 headers there are quite a few that relate to sockets; AcceptEx(), ConnectEx(), DisconnectEx(), TransmitFile(), the HTTP.sys API, the RIO API, etc.

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

You're missing the point. What causes completion packets to be sent is events, not API calls. There are basically only a few TCP events:

  • inbound connection
  • outbound connection complete
  • data
  • write finished
  • timeout
  • end of stream, and
  • error.
user207421
  • 305,947
  • 44
  • 307
  • 483
0

Copied from the site

Supported I/O Functions

The following functions can be used to start I/O operations that complete by using I/O completion ports. You must pass the function an instance of the OVERLAPPED structure and a file handle previously associated with an I/O completion port (by a call to CreateIoCompletionPort) to enable the I/O

completion port mechanism:

  1. ConnectNamedPipe
  2. DeviceIoControl
  3. LockFileEx
  4. ReadDirectoryChangesW
  5. ReadFile
  6. TransactNamedPipe
  7. WaitCommEvent
  8. WriteFile
  9. WSASendMsg
  10. WSASendTo
  11. WSASend
  12. WSARecvFrom
  13. WSARecvMsg
  14. WSARecv
benG
  • 82
  • 9