游戏开发论坛

 找回密码
 立即注册
搜索
查看: 7549|回复: 1

Socket recv MSG_WAITALL问题

[复制链接]

31

主题

249

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
发表于 2009-1-31 12:02:00 | 显示全部楼层 |阅读模式
刚刚接触Socket编程,想请教下:
我用TCP阻塞,目的是用recv接收一个完整的struct,recv设置MSG_WAITALL之后,总是立即返回SOCKET_ERROR,WSAGetLastError()返回WSAEOPNOTSUPP。

MSDN文档说
MSG_WAITALL The receive request will complete only when one of the following events occurs:

A. The buffer supplied by the caller is completely full.
B. The connection has been closed.
C. The request has been canceled or an error occurred.

Note that if the underlying transport does not support MSG_WAITALL, or if the socket is in a non-blocking mode, then this call will fail with WSAEOPNOTSUPP. Also, if MSG_WAITALL is specified along with MSG_OOB, MSG_PEEK, or MSG_PARTIAL, then this call will fail with WSAEOPNOTSUPP. This flag is not supported on datagram sockets or message-oriented CO sockets.

是不是这个原因:“Note that if the underlying transport does not support MSG_WAITALL,”?

31

主题

249

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
 楼主| 发表于 2009-2-1 09:24:00 | 显示全部楼层

Re:Socket recv MSG_WAITALL问题

对这里的冷清无奈了。
自己找到了答案。看得懂英文的自己翻译去吧。
http://www.mail-archive.com/cygwin@cygwin.com/msg84243.html

On Nov 28 08:31, patrick ficheux wrote:
> Hi,
>
> I want to use recv() with MSG_WAITALL flag. But this constant isn't defined
> in cygwin.
> I find a old message about this issue here =>
> http://www.cygwin.com/ml/cygwin/2000-06/msg01229.html
>
> Why MSG_WAITALL is not present in cygwin ?
> It's a posix compliance problem ?

No, it's a Winsock compliance problem.  Actually the MSG_WAITALL flag
showed up for the first time in Windows 2003 Server.  So, if you rely on
this flag, your application might break when running on any earlier
Windows version up to and including Windows XP.

There are also no considerations in Cygwin's recv implementation to
emulate the MSG_WAITALL behaviour.  I put that on my TODO list for a
later Cygwin version, though.  For now you're better off with a recv
loop in your application which ensures that the right number of bytes
are read.


Corinna

--
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-20 10:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表