IOCP中使用getpeername出错,返回10014的解决方法。
来源:互联网 发布:matlab 矩阵列归一化 编辑:程序博客网 时间:2024/06/09 18:55
IOCP中使用getpeername出错, WSAGetLastError 的返回值是10014。
与朋友讨论后,经指点。得到此解决方法。记录并致谢。
此问题不是在所有电脑上都会出现。我自己的Win7 x86会出现此错误。到我朋友的Win7 x86中却运行正常。在Windows Server2008 R2 x64 中测试也正常。
原代码:
sockaddr_in sockAddr;memset(&sockAddr, 0, sizeof(sockAddr));socklen_t nSockAddrLen = sizeof(sockAddr);if ( SOCKET_ERROR == getpeername( m_hSocket, (sockaddr*)&sockAddr, &nSockAddrLen ) ) {return false;}m_nWanPort = ntohs(sockAddr.sin_port);m_strWanIP = inet_ntoa(sockAddr.sin_addr);
经查MSDN
http://msdn.microsoft.com/en-us/library/ms737524(VS.85).aspx
里面提及
The buffer size for the local and remote address must be 16 bytes more than the size of the sockaddr structure for the transport protocol in use because the addresses are written in an internal format. For example, the size of a sockaddr_in (the address structure for TCP/IP) is 16 bytes. Therefore, a buffer size of at least 32 bytes must be specified for the local and remote addresses.
sockaddr_in sockAddr[2];memset(&sockAddr, 0, sizeof(sockAddr));socklen_t nSockAddrLen = sizeof(sockAddr);if ( SOCKET_ERROR == getpeername( m_hSocket, (sockaddr*)&sockAddr, &nSockAddrLen ) ) {return false;}m_nWanPort = ntohs(sockAddr[0].sin_port);m_strWanIP = inet_ntoa(sockAddr[0].sin_addr);
修改后,经测试正常。但想不明白为什么我朋友的系统中运行起原来的代码也是正常的。如有了解的同仁请告知。
0 0
- IOCP中使用getpeername出错,返回10014的解决方法。
- IOCP 中WSARecvFrom返回10045的问题
- getsockname与getpeername的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- getsockname函数与getpeername函数的使用
- Python3中使用map()结果出错的解决方法
- IOCP中的AcceptEx与getsockname,getpeername
- 线程中使用UpdateData出错解决方法
- 线程中使用UpdateData出错解决方法
- 线程中使用UpdateData出错解决方法
- 工作线程中使用UpdateData出错解决方法
- 线程中使用UpdateData出错解决方法
- 【笔记】IOCP投递WSARecv失败10014的解决方法
- 排序2-快速排序
- 15周项目一工资数据输入(以ctrl+z)结束版
- 如何学好web前端技术 学好web前端需要什么基础
- Go string to ascii byte array
- 《Python核心编程》第11章 函数和函数式编程 练习
- IOCP中使用getpeername出错,返回10014的解决方法。
- 启动填报任务
- The Swift Programming Language中文版 ----About Swift
- Compiling 64-bit FFmpeg on Mac OS X Lion or Snow Leopard
- Debug与Trace工具类的应用
- 填报表的权限控制
- 基本知识——2014.6.3
- [C/C++]使用socket套接字的通信编程(包括MAKEWORD(2,2)使用等)
- 怎么恢复移动硬盘里删除的文件呢