summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2007-05-16 19:13:34 +0000
committerDwayne Boone <dwayne@zeroc.com>2007-05-16 19:13:34 +0000
commitd87f468730fd906d062e982bc401e450649d5576 (patch)
tree3a3c46780a818eeaa1ed3bea63593121ed9337c2 /cpp
parentBug 1625 - unused property warning (diff)
downloadice-d87f468730fd906d062e982bc401e450649d5576.tar.bz2
ice-d87f468730fd906d062e982bc401e450649d5576.tar.xz
ice-d87f468730fd906d062e982bc401e450649d5576.zip
Bug 1996 - multihomed hostnames
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES4
-rw-r--r--cpp/src/Ice/Network.cpp32
-rw-r--r--cpp/src/Ice/Network.h1
-rw-r--r--cpp/src/Ice/TcpEndpointI.cpp22
-rw-r--r--cpp/src/Ice/UdpEndpointI.cpp22
-rw-r--r--cpp/src/IceSSL/EndpointI.cpp22
6 files changed, 100 insertions, 3 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 0aaf25ced36..4d6c32f6633 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,10 @@
Changes since version 3.2.X (binary incompabible)
-------------------------------------------------
+- If a client endpoint configuration contains a host which is multihomed,
+ the client will now use all the available ip addresses. Previously,
+ only the first in the address list was used and others were ignored.
+
- Added a new property, Ice.Warn.UnusedProperties. If set to 1, when
the communicator is destroyed a warning will be printed listing all
properties that were set, but never read. Default is 0.
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index 33bfec5739f..6e907c4bdbe 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -1260,6 +1260,38 @@ IceInternal::addrToString(const struct sockaddr_in& addr)
}
vector<string>
+IceInternal::getHosts(const string& host)
+{
+ vector<string> result;
+ struct hostent* he = 0;
+ int retry = 5;
+
+ do
+ {
+ he = gethostbyname(host.c_str());
+ }
+ while(he == 0 && h_errno == TRY_AGAIN && --retry >= 0);
+
+ if(he == 0)
+ {
+ DNSException ex(__FILE__, __LINE__);
+ ex.error = h_errno;
+ ex.host = host;
+ throw ex;
+ }
+
+ char** ptr = he->h_addr_list;
+ while(*ptr)
+ {
+ struct in_addr* addr = reinterpret_cast<in_addr*>(*ptr);
+ result.push_back(inet_ntoa(*addr));
+ ptr++;
+ }
+
+ return result;
+}
+
+vector<string>
IceInternal::getLocalHosts()
{
vector<string> result;
diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h
index 6ee6c80d72f..f03836965c6 100644
--- a/cpp/src/Ice/Network.h
+++ b/cpp/src/Ice/Network.h
@@ -107,6 +107,7 @@ ICE_API void fdToLocalAddress(SOCKET, struct sockaddr_in&);
ICE_API bool fdToRemoteAddress(SOCKET, struct sockaddr_in&);
ICE_API std::string addrToString(const struct sockaddr_in&);
+ICE_API std::vector<std::string> getHosts(const std::string&);
ICE_API std::vector<std::string> getLocalHosts();
#ifdef _WIN32
ICE_API std::vector<struct sockaddr_in> getLocalAddresses();
diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp
index 6cf54872826..1c336cb8afc 100644
--- a/cpp/src/Ice/TcpEndpointI.cpp
+++ b/cpp/src/Ice/TcpEndpointI.cpp
@@ -327,7 +327,27 @@ IceInternal::TcpEndpointI::expand(bool server) const
}
else
{
- endps.push_back(const_cast<TcpEndpointI*>(this));
+ if(!server)
+ {
+
+ vector<string> hosts = getHosts(_host);
+ if(hosts.size() > 1)
+ {
+ for(unsigned int i = 0; i < hosts.size(); ++i)
+ {
+ endps.push_back(
+ new TcpEndpointI(_instance, hosts[i], _port, _timeout, _connectionId, _compress, true));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<TcpEndpointI*>(this));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<TcpEndpointI*>(this));
+ }
}
return endps;
}
diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp
index 6681e8becbf..0eef033dd06 100644
--- a/cpp/src/Ice/UdpEndpointI.cpp
+++ b/cpp/src/Ice/UdpEndpointI.cpp
@@ -492,7 +492,27 @@ IceInternal::UdpEndpointI::expand(bool server) const
}
else
{
- endps.push_back(const_cast<UdpEndpointI*>(this));
+ if(!server)
+ {
+
+ vector<string> hosts = getHosts(_host);
+ if(hosts.size() > 1)
+ {
+ for(unsigned int i = 0; i < hosts.size(); ++i)
+ {
+ endps.push_back(
+ new UdpEndpointI(_instance, hosts[i], _port, _connect, _connectionId, _compress, true));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<UdpEndpointI*>(this));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<UdpEndpointI*>(this));
+ }
}
return endps;
}
diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp
index 69866544132..a14f152f3e1 100644
--- a/cpp/src/IceSSL/EndpointI.cpp
+++ b/cpp/src/IceSSL/EndpointI.cpp
@@ -327,7 +327,27 @@ IceSSL::EndpointI::expand(bool server) const
}
else
{
- endps.push_back(const_cast<EndpointI*>(this));
+ if(!server)
+ {
+
+ vector<string> hosts = IceInternal::getHosts(_host);
+ if(hosts.size() > 1)
+ {
+ for(unsigned int i = 0; i < hosts.size(); ++i)
+ {
+ endps.push_back(
+ new EndpointI(_instance, hosts[i], _port, _timeout, _connectionId, _compress, true));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<EndpointI*>(this));
+ }
+ }
+ else
+ {
+ endps.push_back(const_cast<EndpointI*>(this));
+ }
}
return endps;
}