summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Network.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2013-02-20 08:59:54 +0100
committerBenoit Foucher <benoit@zeroc.com>2013-02-20 08:59:54 +0100
commitd6c9c999967db8e36bd1c626e0977e0de84c267e (patch)
tree2c0569d899d4a8f1c902c7b0df8ba03e845cd925 /cpp/src/Ice/Network.cpp
parentFixed ICE-5267 - don't run metrics test when IPv6 enabled (diff)
downloadice-d6c9c999967db8e36bd1c626e0977e0de84c267e.tar.bz2
ice-d6c9c999967db8e36bd1c626e0977e0de84c267e.tar.xz
ice-d6c9c999967db8e36bd1c626e0977e0de84c267e.zip
Fixed ICE-5265 - Catch exceptions from HostName construction
Diffstat (limited to 'cpp/src/Ice/Network.cpp')
-rw-r--r--cpp/src/Ice/Network.cpp61
1 files changed, 33 insertions, 28 deletions
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index 34c7ec09b2c..9754769479a 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -578,14 +578,32 @@ IceInternal::errorToStringDNS(int error)
vector<Address>
IceInternal::getAddresses(const string& host, int port, ProtocolSupport, Ice::EndpointSelectionType, bool, bool)
{
- vector<Address> result;
- Address addr;
- addr.host = ref new HostName(host.empty() ? "localhost" : ref new String(IceUtil::stringToWstring(host).c_str()));
- stringstream os;
- os << port;
- addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
- result.push_back(addr);
- return result;
+ try
+ {
+ vector<Address> result;
+ Address addr;
+ if(host.empty())
+ {
+ addr.host = ref new HostName("localhost");
+ }
+ else
+ {
+ addr.host = ref new HostName(ref new String(IceUtil::stringToWstring(host).c_str()));
+ }
+ stringstream os;
+ os << port;
+ addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
+ result.push_back(addr);
+ return result;
+ }
+ catch(Platform::Exception^ pex)
+ {
+ DNSException ex(__FILE__, __LINE__);
+ ex.error = (int)SocketError::GetStatus(pex->HResult);
+ ex.host = host;
+ throw ex;
+ }
+
}
#else
vector<Address>
@@ -725,25 +743,6 @@ IceInternal::getProtocolSupport(const Address& addr)
}
#endif
-#ifdef ICE_OS_WINRT
-Address
-IceInternal::getAddressForServer(const string& host, int port, ProtocolSupport, bool)
-{
- Address addr;
- ostringstream os;
- os << port;
- addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
- if(host.empty())
- {
- addr.host = nullptr; // Equivalent of inaddr_any, see doBind implementation.
- }
- else
- {
- addr.host = ref new HostName(ref new String(IceUtil::stringToWstring(host).c_str()));
- }
- return addr;
-}
-#else
Address
IceInternal::getAddressForServer(const string& host, int port, ProtocolSupport protocol, bool preferIPv6)
{
@@ -754,6 +753,12 @@ IceInternal::getAddressForServer(const string& host, int port, ProtocolSupport p
if(host.empty())
{
Address addr;
+#ifdef ICE_OS_WINRT
+ ostringstream os;
+ os << port;
+ addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
+ addr.host = nullptr; // Equivalent of inaddr_any, see doBind implementation.
+#else
memset(&addr.saStorage, 0, sizeof(sockaddr_storage));
if(protocol != EnableIPv4)
{
@@ -767,11 +772,11 @@ IceInternal::getAddressForServer(const string& host, int port, ProtocolSupport p
addr.saIn.sin_port = htons(port);
addr.saIn.sin_addr.s_addr = htonl(INADDR_ANY);
}
+#endif
return addr;
}
return getAddresses(host, port, protocol, Ice::Ordered, preferIPv6, true)[0];
}
-#endif
int
IceInternal::compareAddress(const Address& addr1, const Address& addr2)