重叠套接字 IO 中的错误处理

发布于 2024-11-07 15:25:33 字数 424 浏览 5 评论 0原文

在使用重叠套接字 IO 和 IOCP 的情况下,任何人都可以建议一种可靠的方法来处理系统错误吗?

MSDN在这方面的描述很繁琐。它表示对于 GetQueuedCompletionStatus 返回代码 FALSE,应该有一个后续的 GetLastError 调用来获取失败操作的错误代码。然而,我们知道对于 WSA 函数,应该调用 WSAGetLastErrorGetLastError 在套接字错误时返回 0)。所以问题的第一部分是——它在实践中是如何运作的?

另一个问题是如果通过 GetQueuedCompletionStatusEx 提取完成数据包,则处理错误。 MSDN 仅描述了此调用本身的错误处理,而没有提及获取各个失败操作的错误代码。

预先感谢所有回复和评论。

Can anyone please suggest a reliable way to handle system errors in case of using overlapped socket IO and IOCP?

MSDN description is cumbersome on this aspect. It says that for GetQueuedCompletionStatus return code FALSE there should be a subsequent GetLastError call to get error code on the failed operation. However, we know that for WSA-functions one should call WSAGetLastError instead (GetLastError returns 0 upon a socket error). So the first part of question is - how does it work in practice?

Another problem is handling errors if completion packets are extracted by GetQueuedCompletionStatusEx. MSDN describes only error handling for this call itself, saying nothing about obtaining error codes of individual failed operations.

Thanks in advance for all responses and comments.

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

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

发布评论

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

评论(1

终陌 2024-11-14 15:25:33

经过几个小时用放大镜试验和研究 MSDN 后,我发现了以下内容:

http://msdn.microsoft.com/en-us/library/ms684342%28v=VS.85%29.aspx(一篇关于重叠结构的文章,内部描述字段):

I/O 请求的错误代码。当发出请求时,系统将此成员设置为STATUS_PENDING,以指示操作尚未开始。当请求完成时,系统将此成员设置为已完成请求的错误代码。

内部成员最初保留供系统使用,其行为可能会改变。

最后一句话看起来不太好,但我想就是这样。

After few hours of experimenting and studying MSDN with a magnifying glass I've found the following:

http://msdn.microsoft.com/en-us/library/ms684342%28v=VS.85%29.aspx (an article on OVERLAPPED structure, description of the Internal field):

The error code for the I/O request. When the request is issued, the system sets this member to STATUS_PENDING to indicate that the operation has not yet started. When the request is completed, the system sets this member to the error code for the completed request.

The Internal member was originally reserved for system use and its behavior may change.

The last phrase doesn't look good, but I guess it is what it is.

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