0

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?

Arre
  • 125
  • 1
  • 7
  • 1
    There is no good reason to change an IOCP's completion key. For whatever reason you think you need that, rethink your approach instead. As for `AcceptEx()`, if you instruct it to receive data after accepting a connection, its completion will not be notified until that data has been received. This is clearly stated in the [documentation](https://learn.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-acceptex): "***If a receive buffer is provided**, the overlapped operation will not complete until a connection is accepted **and data is read**.*". – Remy Lebeau Jun 02 '20 at 23:20
  • 1
    The same goes for any I/O operation you perform - its completion is not notified until the ENTIRE operation is finished. As for the Client, I don't understand what you are asking for that. Are you asking how to get a completion notification on the client side when it sends data to the server? You can use an IOCP on the client side with `ConnectEx()` or `WSASend()`. – Remy Lebeau Jun 02 '20 at 23:21

1 Answers1

1

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

RbMm
  • 31,280
  • 3
  • 35
  • 56
  • Is it possible to use `NtSetInformationFile` in regular windows application? Is this reserved for drivers? – Alex Sep 11 '20 at 17:45