CreateIoCompletionPort()
is used to associate a socket with a completion port. However, when this socket is closed, then I need to "un-associate" it from the completion port. How can I do that?
Microsoft obviously doesn’t want ordinary users to do it, but nonetheless, there is an officially documented way (and it only required a madton of digging to find it):
Calling NtSetInformationFile
, passing the value FileReplaceCompletionInformation
for the FileInformationClass
parameter, will get it done. (This value is defined in FILE_INFORMATION_CLASS
)
A copy of the description for this parameter value (emphasis mine):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With