WinSock recvfrom/WSARecvFrom返回WSAECONNRESET(10054)解决
来源:互联网 发布:可以录像的软件 编辑:程序博客网 时间:2024/04/30 04:08
当在使用UDP的时候,如果碰到recvfrom/WSARecvFrom返回WSAECONNRESET(10054)时,需要注意。问题的描述可见(www-pc.uni-regensburg.de/systemsw/W2KPRO/UPDATE/POSTSP1/Q263823.htm),详细内容如下:
SYMPTOMS
In Windows 2000, a User Datagram Protocol (UDP) program may not work and may generate a WSAECONNRESET response.
CAUSE
If sending a datagram using the sendto function results in an "ICMP port unreachable" response and the select function is set for readfds, the program returns 1 and the subsequent call to the recvfrom function does not work with a WSAECONNRESET (10054) error response. In Microsoft Windows NT 4.0, this situation causes the select function to block or time out.
RESOLUTION
A new sockets IOCTL called "SIO_UDP_CONNRESET" has been introduced in Windows 2000. When this IOCTL is used, the program must be rewritten specifically for Windows 2000 to obtain the original Windows NT 4.0 behavior. Windows NT 4.0, Microsoft Windows 95, and Microsoft Windows 98 have no support for this new IOCTL. In addition to rewriting your application, you will need the hotfix referenced further down in this article.
The following code snippet demonstrates a technique that can be used to call WSAIoctl with the SIO_UDP_CONNRESET control code to obtain the original Windows NT 4.0 behavior:
DWORDdwBytesReturned = 0;
BOOLbNewBehavior = FALSE;
DWORDstatus;
// disable new behavior using
// IOCTL: SIO_UDP_CONNRESET
status = WSAIoctl(sd, SIO_UDP_CONNRESET,
&bNewBehavior, sizeof(bNewBehavior),
NULL, 0, &dwBytesReturned,
NULL, NULL);
if (SOCKET_ERROR == status)
{
DWORD dwErr = WSAGetLastError();
if (WSAEWOULDBLOCK == dwErr)
{
// nothing to do
return(FALSE);
}
else
{
printf("WSAIoctl(SIO_UDP_CONNRESET) Error: %d/n", dwErr);
return(FALSE);
}
}
To be able to compile this code, you need either to have the latest Mswsock.h which includes the definition of SIO_UDP_CONNRESET or to insert below definition of it directly into your code:
// MS Transport Provider IOCTL to control
// reporting PORT_UNREACHABLE messages
// on UDP sockets via recv/WSARecv/etc.
// Path TRUE in input buffer to enable (default if supported),
// FALSE to disable.
#defineSIO_UDP_CONNRESET_WSAIOW(IOC_VENDOR,12)
NOTE: The hotfix that is described in this article will not resolve the problem unless the program is rewritten to use the new SIO_UDP_CONNRESET IOCTL.
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
Q263823 WinSock Recvfrom() Now Returns WSAECONNRESET Instead of Blocking or Timing Out
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article
- WinSock recvfrom/WSARecvFrom返回WSAECONNRESET(10054)解决
- CSocket Recvfrom() 返回错误 WSAECONNRESET
- UDP套接字调用recvfrom返回WSAECONNRESET(10054)
- WinSock Recvfrom() 现在返回 WSAECONNRESET 代替阻止或超时(WSAIoctl中的SIO_UDP_CONNRESET参数)
- Recvfrom() 返回 WSAECONNRESET 代替阻塞或超时
- WinSock Recvfrom() now returns WSAECONNRESET instead of blocking or timing out
- sendto、WSASendto,recvfrom、WSARecvfrom 区别?
- sendto、WSASendto,recvfrom、WSARecvfrom 区别?
- WSARecvFrom()
- IOCP 中WSARecvFrom返回10045的问题
- 使用recvfrom()函数,返回10054错误的问题
- Windows UDP socket recvfrom返回10054错误的解决办法
- Windows UDP socket recvfrom返回10054错误的解决办法
- 解决 recvfrom的 阻塞
- recvfrom为何老是返回-1
- 解决recvfrom阻塞接受问题
- recvfrom error 10054
- recvfrom()
- 浅析DHCP
- 理财领域各种“潜规则”
- BOOTP:引导协议 (Bootstrap Protocol)
- LoadRunner监视的性能计数器
- 投资分析、风险管理与投资心理
- WinSock recvfrom/WSARecvFrom返回WSAECONNRESET(10054)解决
- Java 技术小图谱
- 投资大师经典名人名言
- .net与Java 各个框架之间的对应关系
- 软件开发的葵花宝典(转载)
- 整理的一些ExtJS学习资料
- Servlet与XML的配置问题及相关例子
- 纸黄金投资五大要素
- 古代奥运会创始人是谁?