重叠 IO 和 ERROR_IO_INCOMPLETE

发布于 2024-10-04 11:47:37 字数 441 浏览 2 评论 0原文

我已经重叠 IO 工作了两年了,但我将它与一个新应用程序一起使用,并且它向我抛出了这个错误(当我隐藏主窗体时)。

我已经用谷歌搜索过,但我无法理解该错误的含义以及我应该如何处理它?

有什么想法吗?

我在 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨夜星沙 2024-10-11 11:47:37

ERROR_IO_INCOMPLETE 是一个错误代码,表示 Overlapped 操作仍在进行中; GetOverlappedResult 返回 false,因为操作尚未成功。

您有两种选择 - 阻塞和非阻塞:

阻塞直到操作完成:GetOverlappedResult 调用更改为:

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

这可确保 Overlapped 操作已完成(即成功或失败) ) 在返回结果之前。

轮询完成:如果操作仍在进行中,您可以从函数返回,并在等待结果的同时执行其他工作:

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 */
}

通常,第二个选项比第一个选项更好,因为它确实如此不会导致您的应用程序停止并等待结果。 (但是,如果代码在单独的线程上运行,则第一个选项可能更可取。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文