diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-05-16 19:13:34 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-05-16 19:13:34 +0000 |
commit | d87f468730fd906d062e982bc401e450649d5576 (patch) | |
tree | 3a3c46780a818eeaa1ed3bea63593121ed9337c2 /cpp/src | |
parent | Bug 1625 - unused property warning (diff) | |
download | ice-d87f468730fd906d062e982bc401e450649d5576.tar.bz2 ice-d87f468730fd906d062e982bc401e450649d5576.tar.xz ice-d87f468730fd906d062e982bc401e450649d5576.zip |
Bug 1996 - multihomed hostnames
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Network.cpp | 32 | ||||
-rw-r--r-- | cpp/src/Ice/Network.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/TcpEndpointI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/Ice/UdpEndpointI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/IceSSL/EndpointI.cpp | 22 |
5 files changed, 96 insertions, 3 deletions
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; } |