无法分配请求的地址 - 可能的原因? [英] Cannot assign requested address - possible causes?

查看:51
本文介绍了无法分配请求的地址 - 可能的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由主服务器和分布式从服务器组成的程序.从服务器向服务器发送状态更新,如果服务器在固定时间段内没有收到特定从服务器的消息,则将该从服务器标记为停机.这一直在发生.

I have a program that consists of a master server and distributed slave servers. The slave servers send status updates to the server, and if the server hasn't heard from a specific slave in a fixed period, it marks the slave as down. This is happening consistently.

通过检查日志,我发现从站只能向服务器发送一个状态更新,然后永远无法发送另一个更新,总是在调用 connect() 时失败无法分配请求的地址(99).

From inspecting logs, I have found that the slave is only able to send one status update to the server, and then is never able to send another update, always failing on the call to connect() "Cannot assign requested address (99).

奇怪的是,从站能够向服务器发送其他几个更新,并且所有连接都发生在同一个端口上.这种失败的最常见原因似乎是连接保持打开状态,但我无法找到任何保持打开状态的东西.还有其他可能的解释吗?

Oddly enough, the slave is able to send several other updates to the server, and all of the connections are happening on the same port. It seems that the most common cause of this failure is that connections are left open, but I'm having trouble finding anything left open. Are there other possible explanations?

为了澄清,这是我的连接方式:

To clarify, here's how I'm connecting:

struct sockaddr *sa; // parameter
size_t           sa_size; //parameter
int              i = 1;
int              stream;

stream = socket(AF_INET,SOCK_STREAM,0);
setsockopt(stream,SOL_SOCKET,SO_REUSEADDR,&i,sizeof(i));
bindresvport(stream,NULL);
connect(stream,sa,sa_size);

此代码位于获取与另一台服务器的连接的函数中,这 4 次调用中的任何一个失败都会导致该函数失败.

This code is in a function to obtain a connection to another server, and a failure on any of those 4 calls causes the function to fail.

推荐答案

也许 SO_REUSEADDR 在这里有帮助?http://www.unixguide.net/network/socketfaq/4.5.shtml

Maybe SO_REUSEADDR helps here? http://www.unixguide.net/network/socketfaq/4.5.shtml

这篇关于无法分配请求的地址 - 可能的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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