C++ recv() with errno=107:(传输端点连接)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2131561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
recv() with errno=107:(transport endpoint connected)
提问by iBacchus
well..I use a typical model of epoll+multithread to handle massive sockets, that is, I have a thread called epollWorkThread that use epoll_wait to handle i/o sockets. While there's an event of EPOLLIN, recv() will do the work and I do use the noblocking mode to allow immediate return. And recv() is indeed in a while(true) loop. Everything is fine in the intial time(maybe a couple of hours or maybe minutes or if I'm lucky days), I can receive the information. But some time later, recv() insists to return -1 with the errno = 107(ENOTCONN). The other peer of the transport is written in AS3 which makes sure that the socket is connected. So I'm confused by the recv() behaviour. Thank you in advance and any comment is appreciated!
嗯..我使用epoll+multithread的典型模型来处理海量socket,也就是我有一个线程叫做epollWorkThread,它使用epoll_wait来处理i/o socket。虽然有 EPOLLIN 事件,但 recv() 会完成工作,我确实使用无阻塞模式来允许立即返回。而 recv() 确实处于 while(true) 循环中。在最初的时间里一切都很好(可能是几个小时或几分钟,或者如果我很幸运的话),我可以收到信息。但一段时间后,recv() 坚持返回 -1 并带有 errno = 107(ENOTCONN)。传输的另一个对等体写入 AS3,以确保套接字已连接。所以我对 recv() 行为感到困惑。在此先感谢您,并感谢您的任何评论!
回答by Axel
Errno 107 means that the socket is NOTconnected (any more). There are several reasons why this could happen. Assuming you're right and both sides of the connection claim that the socket is still open, an intermediate router/switch may have dropped the connection due to a timeout. The safest way to avoid such things from happen is to periodically send a 'health' or 'keep-alive' message. (Thus the intermediate router/switch accepts the connection as living...)=
错误号107名指该套接字NOT连接(任何更多)。发生这种情况的原因有多种。假设你是对的并且连接的双方都声称套接字仍然打开,中间路由器/交换机可能由于超时而断开了连接。避免此类事情发生的最安全方法是定期发送“健康”或“保持活动”消息。(因此中间路由器/交换机接受连接为活动...)=