Skip to main content

get_queued_completion_status

Function get_queued_completion_status 

Source
pub unsafe fn get_queued_completion_status(
    completion_port: &IOCompletionPort,
    lp_number_of_bytes: &mut DWORD,
    lp_completion_key: &mut ULONG_PTR,
    lp_overlapped: *mut *mut OVERLAPPED,
    dw_milliseconds: DWORD,
) -> Result<bool>
Expand description

Retrieves the results of an asynchronous I/O operation on an I/O completion port.

Wraps the unsafe Windows API function GetQueuedCompletionStatus, making it safe to call only when the overlapped buffer remains valid and unchanged anywhere else during the entire async operation.

Returns a boolean indicating whether an I/O operation completed synchronously or is still pending.

ยงSafety

This function is marked as unsafe because it uses raw pointers and requires the caller to ensure that the overlapped buffer stays valid during the whole async operation.

SAFETY: THIS IS NOT ENTIRELY SAFE! PLEASE READ!

This function is thread safe i.e. the same file handle can be used by multiple threads to read from the file as it uses the windows ReadFile API with async mode using OVERLAPPED structure. ReadFile Function - https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile Synchronous and Asynchronous I/O - https://learn.microsoft.com/en-us/windows/win32/FileIO/synchronous-and-asynchronous-i-o

The only caveat is read operation is followed by polling on the handle using GetQueuedCompletionStatus API. If multiple threads are submitting read requests and polling then polling will return the completion status of any of the read requests. This is because GetQueuedCompletionStatus API returns the completion status of any of the read requests that are completed.