summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2004-03-29 23:21:40 +0000
committerMarc Laukien <marc@zeroc.com>2004-03-29 23:21:40 +0000
commit64c22bc624d13bec6e9e88fc6411c0d465bb47db (patch)
tree69d4a68e52cab893fc5763a92f21e87bc9ffd58d
parent*** empty log message *** (diff)
downloadice-64c22bc624d13bec6e9e88fc6411c0d465bb47db.tar.bz2
ice-64c22bc624d13bec6e9e88fc6411c0d465bb47db.tar.xz
ice-64c22bc624d13bec6e9e88fc6411c0d465bb47db.zip
ConnectionRefusedException
-rw-r--r--cpp/CHANGES25
-rw-r--r--cpp/slice/Ice/LocalException.ice11
-rw-r--r--cpp/src/Ice/Exception.cpp7
-rw-r--r--cpp/src/Ice/Network.cpp27
-rw-r--r--cpp/src/Ice/Network.h1
-rw-r--r--cpp/src/IceSSL/SslClientTransceiver.cpp12
-rw-r--r--cpp/src/IceSSL/SslServerTransceiver.cpp2
-rw-r--r--cpp/src/IceSSL/SslTransceiver.cpp4
-rw-r--r--java/CHANGES15
-rw-r--r--java/src/IceInternal/Network.java73
10 files changed, 137 insertions, 40 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 7175c3c6aa5..a25ad6e7871 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,17 +1,20 @@
Changes since version 1.3.0
---------------------------
-- The documentation claimed that the Ice.ProgramName property
- was initialized to the value of argv[0], but that initialization
- was in fact not happening. As of this version, Ice.ProgramName
- is initialized correctly.
-
-- Fixed the slice2cpp compiler for operations with
- multiple exceptions in an exception specification:
- if an exception was a base of one or more other exceptions
- in the same exception specification, the code generator
- sometimes emitted the catch blocks in the marshaling and dispatch
- code in the wrong order.
+- Added ConnectionRefusedException as a specialization of
+ ConnectFailedException, to indicate if a connection fails because a
+ server actively refuses such connection.
+
+- The documentation claimed that the Ice.ProgramName property was
+ initialized to the value of argv[0], but that initialization was in
+ fact not happening. As of this version, Ice.ProgramName is
+ initialized correctly.
+
+- Fixed the slice2cpp compiler for operations with multiple exceptions
+ in an exception specification: if an exception was a base of one or
+ more other exceptions in the same exception specification, the code
+ generator sometimes emitted the catch blocks in the marshaling and
+ dispatch code in the wrong order.
Changes since version 1.2.0
---------------------------
diff --git a/cpp/slice/Ice/LocalException.ice b/cpp/slice/Ice/LocalException.ice
index bca7269cd12..946112fd903 100644
--- a/cpp/slice/Ice/LocalException.ice
+++ b/cpp/slice/Ice/LocalException.ice
@@ -307,6 +307,17 @@ local exception ConnectFailedException extends SocketException
/**
*
+ * This exception is a specialization of [ConnectFailedException] for
+ * connection failures, where the server host actively refuses a
+ * connection.
+ *
+ **/
+local exception ConnectionRefusedException extends ConnectFailedException
+{
+};
+
+/**
+ *
* This exception is a specialization of [SocketException], indicating
* a lost connection.
*
diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp
index 848c7d5f83e..baa83eab316 100644
--- a/cpp/src/Ice/Exception.cpp
+++ b/cpp/src/Ice/Exception.cpp
@@ -205,6 +205,13 @@ Ice::ConnectFailedException::ice_print(ostream& out) const
}
void
+Ice::ConnectionRefusedException::ice_print(ostream& out) const
+{
+ Exception::ice_print(out);
+ out << ":\nconnection refused: " << errorToString(error);
+}
+
+void
Ice::ConnectionLostException::ice_print(ostream& out) const
{
Exception::ice_print(out);
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index 3512f7e0633..2924f8aeee4 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -101,6 +101,17 @@ IceInternal::connectFailed()
}
bool
+IceInternal::connectionRefused()
+{
+#ifdef _WIN32
+ int error = WSAGetLastError();
+ return error == WSAECONNREFUSED;
+#else
+ return errno == ECONNREFUSED;
+#endif
+}
+
+bool
IceInternal::connectInProgress()
{
#ifdef _WIN32
@@ -484,7 +495,13 @@ repeatConnect:
#else
errno = val;
#endif
- if(connectFailed())
+ if(connectionRefused())
+ {
+ ConnectionRefusedException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ else if(connectFailed())
{
ConnectFailedException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
@@ -502,7 +519,13 @@ repeatConnect:
}
closeSocket(fd);
- if(connectFailed())
+ if(connectionRefused())
+ {
+ ConnectionRefusedException ex(__FILE__, __LINE__);
+ ex.error = getSocketErrno();
+ throw ex;
+ }
+ else if(connectFailed())
{
ConnectFailedException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h
index 83568571088..60362a24ef0 100644
--- a/cpp/src/Ice/Network.h
+++ b/cpp/src/Ice/Network.h
@@ -79,6 +79,7 @@ ICE_PROTOCOL_API bool acceptInterrupted();
ICE_PROTOCOL_API bool noBuffers();
ICE_PROTOCOL_API bool wouldBlock();
ICE_PROTOCOL_API bool connectFailed();
+ICE_PROTOCOL_API bool connectionRefused();
ICE_PROTOCOL_API bool connectInProgress();
ICE_PROTOCOL_API bool connectionLost();
ICE_PROTOCOL_API bool notConnected();
diff --git a/cpp/src/IceSSL/SslClientTransceiver.cpp b/cpp/src/IceSSL/SslClientTransceiver.cpp
index 4deb7038700..ea90e1c54ef 100644
--- a/cpp/src/IceSSL/SslClientTransceiver.cpp
+++ b/cpp/src/IceSSL/SslClientTransceiver.cpp
@@ -284,14 +284,14 @@ IceSSL::SslClientTransceiver::handshake(int timeout)
else // result == 0
{
//
- // The OpenSSL docs say that a result code of 0 indicates
- // a graceful shutdown. In order to cause a retry in the
- // Ice core, we raise ConnectFailedException. However,
- // errno isn't set in this situation, so we always use
+ // The OpenSSL docs say that a result code of 0
+ // indicates a graceful shutdown. In order to
+ // cause a retry in the Ice core, we raise
+ // ConnectionRefusedException. However, errno
+ // isn't set in this situation, so we always use
// ECONNREFUSED.
//
-
- ConnectFailedException ex(__FILE__, __LINE__);
+ ConnectionRefusedException ex(__FILE__, __LINE__);
#ifdef _WIN32
ex.error = WSAECONNREFUSED;
#else
diff --git a/cpp/src/IceSSL/SslServerTransceiver.cpp b/cpp/src/IceSSL/SslServerTransceiver.cpp
index 3a38180171b..bf05422c09d 100644
--- a/cpp/src/IceSSL/SslServerTransceiver.cpp
+++ b/cpp/src/IceSSL/SslServerTransceiver.cpp
@@ -287,7 +287,7 @@ IceSSL::SslServerTransceiver::handshake(int timeout)
else
{
//
- // NOTE: Should this be ConnectFailedException like in the Client?
+ // NOTE: Should this be ConnectionRefusedException like in the Client?
//
ProtocolException protocolEx(__FILE__, __LINE__);
diff --git a/cpp/src/IceSSL/SslTransceiver.cpp b/cpp/src/IceSSL/SslTransceiver.cpp
index eb42d4d938f..d9595a4a37f 100644
--- a/cpp/src/IceSSL/SslTransceiver.cpp
+++ b/cpp/src/IceSSL/SslTransceiver.cpp
@@ -350,8 +350,8 @@ IceSSL::SslTransceiver::forceHandshake()
close();
- // If the handshake fails, the connection failed.
- ConnectFailedException ex(__FILE__, __LINE__);
+ // If the handshake fails, we consider the connection as refused.
+ ConnectionRefusedException ex(__FILE__, __LINE__);
#ifdef _WIN32
ex.error = WSAECONNREFUSED;
#else
diff --git a/java/CHANGES b/java/CHANGES
index aef2b2d471c..0fa116afd3d 100644
--- a/java/CHANGES
+++ b/java/CHANGES
@@ -1,12 +1,15 @@
Changes since version 1.3.0
---------------------------
-- Fixed the slice2java compiler for operations with
- multiple exceptions in an exception specification:
- if an exception was a base of one or more other exceptions
- in the same exception specification, the code generator
- sometimes emitted the catch blocks in the marshaling and dispatch
- code in the wrong order.
+- Added ConnectionRefusedException as a specialization of
+ ConnectFailedException, to indicate if a connection fails because a
+ server actively refuses such connection.
+
+- Fixed the slice2java compiler for operations with multiple
+ exceptions in an exception specification: if an exception was a base
+ of one or more other exceptions in the same exception specification,
+ the code generator sometimes emitted the catch blocks in the
+ marshaling and dispatch code in the wrong order.
Changes since version 1.2.0
---------------------------
diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java
index 8040f50b248..3ea49d0e511 100644
--- a/java/src/IceInternal/Network.java
+++ b/java/src/IceInternal/Network.java
@@ -20,22 +20,53 @@ public final class Network
connectionLost(java.io.IOException ex)
{
//
- // TODO: The JDK raises a generic IOException for cases
- // that we want to detect. Unfortunately, our only choice
- // is to search the exception message for distinguishing
- // phrases.
+ // TODO: The JDK raises a generic IOException for certain
+ // cases of connection loss. Unfortunately, our only choice is
+ // to search the exception message for distinguishing phrases.
//
- String msg = ex.getMessage();
+
+ String msg = ex.getMessage().toLowerCase();
if(msg != null)
{
final String[] msgs =
{
- "Connection reset by peer", // ECONNRESET
- "Cannot send after socket shutdown", // ESHUTDOWN (Win32)
- "Cannot send after transport endpoint shutdown", // ESHUTDOWN (Linux)
- "Software caused connection abort", // ECONNABORTED
- "An existing connection was forcibly closed" // unknown
+ "connection reset by peer", // ECONNRESET
+ "cannot send after socket shutdown", // ESHUTDOWN (Win32)
+ "cannot send after transport endpoint shutdown", // ESHUTDOWN (Linux)
+ "software caused connection abort", // ECONNABORTED
+ "an existing connection was forcibly closed" // unknown
+ };
+
+ for(int i = 0; i < msgs.length; i++)
+ {
+ if(msg.indexOf(msgs[i]) != -1)
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean
+ connectionRefused(java.net.ConnectException ex)
+ {
+ //
+ // The JDK raises a generic ConnectException when the server
+ // actively refuses a connection. Unfortunately, our only
+ // choice is to search the exception message for
+ // distinguishing phrases.
+ //
+
+ String msg = ex.getMessage().toLowerCase();
+
+ if(msg != null)
+ {
+ final String[] msgs =
+ {
+ "connection refused" // ECONNREFUSED
};
for(int i = 0; i < msgs.length; i++)
@@ -202,7 +233,16 @@ public final class Network
{
// ignore
}
- Ice.ConnectFailedException se = new Ice.ConnectFailedException();
+
+ Ice.ConnectFailedException se;
+ if(connectionRefused(ex))
+ {
+ se = new Ice.ConnectionRefusedException();
+ }
+ else
+ {
+ se = new Ice.ConnectFailedException();
+ }
se.initCause(ex);
throw se;
}
@@ -239,7 +279,16 @@ public final class Network
{
// ignore
}
- Ice.ConnectFailedException se = new Ice.ConnectFailedException();
+
+ Ice.ConnectFailedException se;
+ if(connectionRefused(ex))
+ {
+ se = new Ice.ConnectionRefusedException();
+ }
+ else
+ {
+ se = new Ice.ConnectFailedException();
+ }
se.initCause(ex);
throw se;
}