简体   繁体   English

重叠的IO和ERROR_IO_INCOMPLETE

[英]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). 我已经重叠IO工作了2年了但是我已经将它用于一个新的应用程序并且它把这个错误告诉了我(当我隐藏主要表单时)。

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 我在NamedPipes上使用它,并在调用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; ERROR_IO_INCOMPLETE是一个错误代码,表示重叠操作仍在进行中; GetOverlappedResult returns false as the operation hasn't succeeded yet. 由于操作尚未成功, GetOverlappedResult返回false。

You have two options - blocking and non-blocking: 您有两种选择 - 阻止和非阻止:

Block until the operation completes: change your GetOverlappedResult call to: 阻止操作完成:GetOverlappedResult调用更改为:

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.) (但是,如果代码在单独的线程上运行,则第一个选项可能更可取。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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