Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Un-associate" socket from completion port

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?

like image 864
Tom Avatar asked Dec 14 '22 14:12

Tom


1 Answers

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.

like image 68
Keno Avatar answered Dec 27 '22 21:12

Keno