简体   繁体   中英

Overlapped IO and ERROR_IO_INCOMPLETE

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 after 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 (ie 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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM