处理 WSAENETDOWN
我是 Winsock 编程的新手,我正在尝试学习如何通过 WSAEventSelect() 使用异步套接字。我有点不确定如何处理 WSAENETDOWN 错误。
当我收到 WSAENETDOWN 错误时到底会发生什么?我的套接字和事件对象会自动销毁吗?我需要进行什么样的清理?如果我想尝试重新连接,处理 WSAENETDOWN 错误的正确方法是什么?可以再次调用 connect() 吗?我应该关闭并重新创建套接字和事件对象,还是应该调用 WSACleanup() 并从头开始?
I'm new to Winsock programming and I'm trying to learn how to use asynchronous sockets with WSAEventSelect(). I'm a bit unsure on how to handle a WSAENETDOWN error.
What exactly happens when I get a WSAENETDOWN error? Are my sockets and event objects automatically destroyed? What sort of cleanup do I need to do? What is the proper way of handling a WSAENETDOWN error if I'd like to try to reconnect? Is it ok to call connect() again, should I close and recreate my sockets and event objects, or should I call WSACleanup() and start over from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WSAENETDOWN
表示此套接字上发生网络错误,无法再发送和接收数据。要处理此错误,您应该关闭此套接字。无需关闭其他套接字或 WASCleanup,因为其他套接字仍然可以正常工作(想象一下一台具有两个网卡的计算机,其中一个网络已关闭,但另一个仍然可以正常工作)。套接字和事件不会自动销毁。WSAENETDOWN
means that on this socket a network error occured and sending and receiving data is not possible anymore. To handle this error you should close this one socket. There is no need to close other sockets orWASCleanup
as other sockets can still be functionable (think about a computer with two network cards where one network is down but the other still functions). The sockets and events are not destroyed automatically.