windowswinsockiocpcompletion

Change/Update the CompletionKey


ULONG_PTR CKey = 2; CreateIoCompletionPort(...Ckey...);

Is it possible to change/update the CompletionKey somehow after I called the function? Also, an operation happening on both serversock and clientsock (E.g. AcceptEx in a mode that both accepts and receives) returns completion only for the server, can I change that to the Client or even better to both?


Solution

  • Is it possible to change/update the CompletionKey somehow after I called the function?

    this is possible begin from Windows 8.1

    you need use NtSetInformationFile with FileReplaceCompletionInformation

    Change or remove the I/O completion port for the specified file handle. The caller supplies a pointer to a FILE_COMPLETION_INFORMATION structure that specifies a port handle and a completion key. If the port handle is non-NULL, this handle specifies a new I/O completion port to associate with the file handle. To remove the I/O completion port associated with the file handle, set the port handle in the structure to NULL. To get a port handle, a user-mode caller can call the CreateIoCompletionPort function.

    note that for initial set I/O completion port for the specified file handle we use FileCompletionInformation

    however even if this is possible i think in most case will be wrong and not need do this