0

When using CreateIoCompletionPort() to associate a SOCKET with a completion port, can I pass a direct value (i.e. not a pointer) to the CompletionKey parameter, or should I only pass a pointer?

What I want to do is to pass the SOCKET value.

1 Answers1

3

The CompletionKey parameter to CreateIoCompletionPort is of type ULONG_PTR. It is large enough to hold a ULONG or a pointer type, whichever is larger. You can pass any value, that fits in a ULONG_PTR. A SOCKET meets this requirement.

See winsock2.h:

typedef UINT_PTR SOCKET;
IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • So the concept of passing a direct value to a parameter that expects a pointer is not wrong in any way? –  Jul 13 '15 at 23:37
  • 1
    @joseph_m: The `CompletionKey` parameter is not a pointer. It's just **pointer-sized**, allowing to pass a pointer, if desired. As long as you adhere to alignment and size restrictions, you can pass any value through `CompletionKey`, including a pointer. – IInspectable Jul 13 '15 at 23:45