简体   繁体   中英

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?

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.

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.

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