简体   繁体   English

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

[英]Error handling in overlapped socket IO

Can anyone please suggest a reliable way to handle system errors in case of using overlapped socket IO and IOCP? 在使用重叠的套接字IO和IOCP的情况下,有人可以建议一种可靠的方法来处理系统错误吗?

MSDN description is cumbersome on this aspect. MSDN在这方面的描述很麻烦。 It says that for GetQueuedCompletionStatus return code FALSE there should be a subsequent GetLastError call to get error code on the failed operation. 它说,对于GetQueuedCompletionStatus返回代码FALSE,应该随后进行GetLastError调用,以获取失败操作的错误代码。 However, we know that for WSA-functions one should call WSAGetLastError instead ( GetLastError returns 0 upon a socket error). 但是,我们知道,对于WSA函数,应该改为调用WSAGetLastError (在套接字错误时GetLastError返回0)。 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 . 如果由GetQueuedCompletionStatusEx提取完成数据包,则另一个问题是处理错误。 MSDN describes only error handling for this call itself, saying nothing about obtaining error codes of individual failed operations. MSDN仅描述了此调用本身的错误处理,没有说明获取各个失败操作的错误代码。

Thanks in advance for all responses and comments. 预先感谢您的所有回复和评论。

After few hours of experimenting and studying MSDN with a magnifying glass I've found the following: 经过几个小时的放大镜实验和研究MSDN,我发现了以下内容:

http://msdn.microsoft.com/en-us/library/ms684342%28v=VS.85%29.aspx (an article on OVERLAPPED structure, description of the Internal field): http://msdn.microsoft.com/zh-cn/library/ms684342%28v=VS.85%29.aspx (有关OVERLAPPED结构的文章, Internal字段的说明):

The error code for the I/O request. I / O请求的错误代码。 When the request is issued, the system sets this member to STATUS_PENDING to indicate that the operation has not yet started. 发出请求后,系统将此成员设置为STATUS_PENDING以指示该操作尚未开始。 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. 最后一句话看起来不太好,但我想它就是它的意思。

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

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