开发者

Overlapped IO and ERROR_IO_INCOMPLETE

开发者 https://www.devze.com 2023-01-27 01:38 出处:网络
I have had overlapped IO working for 2 years now but ive used it with a new application and its chucking this error at me (when i hide the main form).

I have had overlapped IO working for 2 years now but ive used it with a new application and its chucking this error at me (when i hide the main form).

I have googled but i fail to understand what the error means and how i should handle it?

Any ideas?

Im using this over NamedPipes and the error happens a开发者_Python百科fter calling GetOverlappedResult

DWORD dwWait = WaitForMultipleObjects(getNumEvents(), m_hEventsArr, FALSE, 500);

//check result. Get correct data

BOOL fSuccess = GetOverlappedResult(data->hPipe, &data->oOverlap, &cbRet, FALSE);

// error happens here


ERROR_IO_INCOMPLETE is an error code that means that the Overlapped operation is still in progress; GetOverlappedResult returns false as the operation hasn't succeeded yet.

You have two options - blocking and non-blocking:

Block until the operation completes: change your GetOverlappedResult call to:

BOOL fSuccess = GetOverlappedResult(data->hPipe, &data->oOverlap, &cbRet, TRUE);

This ensures that the Overlapped operation has completed (i.e. succeeds or fails) before returning the result.

Poll for completion: if the operation is still in progress, you can return from the function, and perform other work while waiting for the result:

BOOL fSuccess = GetOverlappedResult(data->hPipe, &data->oOverlap, &cbRet, FALSE);
if (!fSuccess) {
    if (GetLastError() == ERROR_IO_INCOMPLETE) return; // operation still in progress

    /* handle error */
} else {
    /* handle success */
}

Generally, the second option is preferable to the first, as it does not cause your application to stop and wait for a result. (If the code is running on a separate thread, however, the first option may be preferable.)

0

精彩评论

暂无评论...
验证码 换一张
取 消