为什么 connect() 会给 EADDRNOTAVAIL? [英] Why would connect() give EADDRNOTAVAIL?

查看:24
本文介绍了为什么 connect() 会给 EADDRNOTAVAIL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中出现了一个似乎无法重现的故障.我有一个失败的 TCP 套接字连接,应用程序试图重新连接它.在尝试重新连接的 connect() 的第二次调用中,我得到了一个错误结果 errno == EADDRNOTAVAIL,connect() 的手册页表示:指定的地址在本地机器上不可用."

I have in my application a failure that arose which does not seem to be reproducible. I have a TCP socket connection which failed and the application tried to reconnect it. In the second call to connect() attempting to reconnect, I got an error result with errno == EADDRNOTAVAIL which the man page for connect() says means: "The specified address is not available from the local machine."

看connect()的调用,第二个参数好像是错误所指的地址,但据我了解,这个参数是远程主机的TCP套接字地址,所以我很困惑关于参考本地机器的手册页.是不是我的本地机器上没有远程 TCP 套接字主机的这个地址?如果是这样,为什么会这样?它必须在连接失败之前第一次成功调用 connect() 并尝试重新连接并出现此错误.connect() 的参数两次相同.

Looking at the call to connect(), the second argument appears to be the address to which the error is referring to, but as I understand it, this argument is the TCP socket address of the remote host, so I am confused about the man page referring to the local machine. Is it that this address to the remote TCP socket host is not available from my local machine? If so, why would this be? It had to have succeeded calling connect() the first time before the connection failed and it attempted to reconnect and got this error. The arguments to connect() were the same both times.

这个错误是否是暂时的,如果我等待足够长的时间,如果我再次尝试调用 connect 可能会消失?如果没有,我应该如何尝试从这次失败中恢复?

Would this error be a transient one which, if I had tried calling connect again might have gone away if I waited long enough? If not, how should I try to recover from this failure?

推荐答案

查看此链接

http://www.toptip.ca/2010/02/linux-eaddrnotavail-address-not.html

编辑:是的,我想添加更多,但由于紧急情况不得不在那里剪掉

EDIT: Yes I meant to add more but had to cut it there because of an emergency

您是否在尝试重新连接之前关闭了套接字?关闭将告诉系统套接字对(ip/端口)现在是空闲的.

Did you close the socket before attempting to reconnect? Closing will tell the system that the socketpair (ip/port) is now free.

这里还有一些额外的项目:

Here are additional items too look at:

  • 如果本地端口已经连接到给定的远程 IP 和端口(即,已经存在相同的套接字对),您将收到此错误(请参阅下面的错误链接).
  • 绑定一个不是本地地址的套接字地址会产生这个错误.如果机器的 IP 地址为 127.0.0.1 和 1.2.3.4,而您尝试绑定到 1.2.3.5,则会出现此错误.
  • EADDRNOTAVAIL:指定的地址在远程机器上不可用或名称结构的地址字段全为零.

链接与您类似的错误(答案接近底部)

Link with a bug similar to yours (answer is close to the bottom)

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4294599

似乎您的套接字基本上停留在 TCP 内部状态之一,并且增加重新连接的延迟可能会解决您的问题,就像他们在该错误报告中所做的那样.

It seems that your socket is basically stuck in one of the TCP internal states and that adding a delay for reconnection might solve your problem as they seem to have done in that bug report.

这篇关于为什么 connect() 会给 EADDRNOTAVAIL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆