WSAGetOverlappedResult 函数的问题

KevinHo 2014-06-10 09:12:36
函数原型如下


BOOL WSAAPI WSAGetOverlappedResult(
_In_ SOCKET s,
_In_ LPWSAOVERLAPPED lpOverlapped,
_Out_ LPDWORD lpcbTransfer,
_In_ BOOL fWait,
_Out_ LPDWORD lpdwFlags
);


在MSDN上看到这样的两处描述:
fWait [in]
If TRUE, the function does not return until the operation has been completed. If FALSE and the operation is still pending, the function returns FALSE and the WSAGetLastError function returns WSA_IO_INCOMPLETE.

第二处在Remarks部分,
A pending operation is indicated when the function that started the operation returns FALSE and the WSAGetLastError function returns WSA_IO_PENDING

这里我想请教各位的是,对未完成的异步I/O请求进行这个API调用时,并且对对参数 fWait 传入 FALSE,获取的错误码究竟是 WSA_IO_INCOMPLETE ,还是 WSA_IO_PENDING ?

另外,还有个问题,CancelIOEx(),这个API能否真的用于套接字上的所有异步I/O的请求?我自己测试了下,貌似可以,但是调用过此API后,相应套接字上的所有重叠I/O的WSAOVERLAPPED结构的Internal成员的值会被填充为3221225760,这个值代表什么呢?

请各位高手不吝赐教
...全文
986 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xian_wwq 2014-06-13
  • 打赏
  • 举报
回复
对CancelIOEx()这个方法也有些疑惑,同问。 我在处理的时候,跳过这一步,有问题直接关闭socket 因为socket被close,这个socket上的投递自然就都 返回了。
____Zhang 2014-06-13
  • 打赏
  • 举报
回复
因为 异步I/O操作尚未完成 所以 没办法立即成功 WSAGetOverlappedResult 一般都会io完成后调用
KevinHo 2014-06-12
  • 打赏
  • 举报
回复
引用 1 楼 VisualEleven 的回复:
#define WSA_IO_INCOMPLETE (WSAEWOULDBLOCK) #define WSA_IO_PENDING (WSAEWOULDBLOCK) 3221225760 = C0000120 STATUS_CANCELLED
很感激对 3221225760 的解释 只是WSA_IO_PENDING和WSA_IO_INCOMPLETE还是比较困惑 MSDN上的Windows Sockets Error Codes上有这样的描述: WSA_IO_INCOMPLETE:Overlapped I/O event object not in signaled state. The application has tried to determine the status of an overlapped operation which is not yet completed. Applications that use WSAGetOverlappedResult (with the fWait flag set to FALSE) in a polling mode to determine when an overlapped operation has completed, get this error code until the operation is complete. WSA_IO_PENDING:Overlapped operations will complete later. The application has initiated an overlapped operation that cannot be completed immediately. A completion indication will be given later when the operation has been completed. 可能,WSA_IO_INCOMPLETE比较好理解,我的理解是,WSAOVERLAPPED结构所代表的那个异步I/O请求还没有完成,仍在进行中。但对于WSAGetOverlappedResult(),错误码是WSA_IO_PENDING,还是挺费解的,这是不是在说WSAGetOverlappedResult()的查询操作没办法立即成功,而不是指它所查询的异步I/O操作尚未完成 不知道我这样的理解对不对?请指导一下
Eleven 2014-06-11
  • 打赏
  • 举报
回复
#define WSA_IO_INCOMPLETE (WSAEWOULDBLOCK) #define WSA_IO_PENDING (WSAEWOULDBLOCK) 3221225760 = C0000120 STATUS_CANCELLED

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧