getaddrinfo() 连续失败并显示 EAI_AGAIN
在我的代码中,我使用的代码如下。
do
{
r = getaddrinfo(host, service, &hints, ret);
}
while (r == EAI_AGAIN);
当测试 getaddrinfo() 连续失败时,循环无法正确终止。
您认为有什么方法可以改进代码吗?我们可以使用计数器来计算它应该循环的次数吗?
另请告诉我 getaddrinfo() 调用返回“EAI_AGAIN”的所有原因。
In my code I am using the code as follows.
do
{
r = getaddrinfo(host, service, &hints, ret);
}
while (r == EAI_AGAIN);
when testing getaddrinfo() continuously fails thus loop not terminates properly.
Do you see any way to improve the code? can we use counter to count for number of times it should loop?
Also please let me know for what are all the reasons "EAI_AGAIN" returned by getaddrinfo() call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诚然,这是一个疯狂的猜测。
我们还在功能稍显不足的单核嵌入式系统上看到了这一点。
我假设(在我们的例子中是 dnsmasq)在一个单独的进程中运行,并且出于某种原因(可能是因为我们在追逐尾巴)它没有获得足够的资源(cpu/ram/...)做好它的工作。
对解决方案的大胆猜测可能是在这个紧密循环中加入睡眠,让 DNS 缓存发挥其工作所需的资源。
我会让你知道它是否有效。
Here is, admittedly, a wild guess.
We're also seeing this on a slightly underpowered single core embedded system.
I assume (in our case dnsmasq) is running in a separate process, and for whatever reason (probably because we're running around in circles chasing our tails) it doesn't get enough resources (cpu/ram/...) to do its job.
A wild guess at a solution might be to put a sleep into that tight loop and let the DNS caching magic at the resources it needs to do it's work.
I will let you know if it works.