qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject qpid-cpp git commit: QPID-8221: patch from Chen Wan to add connection timeout to client
Date Wed, 08 Aug 2018 07:13:07 GMT
Repository: qpid-cpp
Updated Branches:
  refs/heads/master 5d0565ab6 -> 5aa108098


QPID-8221: patch from Chen Wan to add connection timeout to client


Project: http://git-wip-us.apache.org/repos/asf/qpid-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-cpp/commit/5aa10809
Tree: http://git-wip-us.apache.org/repos/asf/qpid-cpp/tree/5aa10809
Diff: http://git-wip-us.apache.org/repos/asf/qpid-cpp/diff/5aa10809

Branch: refs/heads/master
Commit: 5aa1080981a657bd6f01483d6b24469e6e838ab5
Parents: 5d0565a
Author: Gordon Sim <gsim@redhat.com>
Authored: Wed Aug 8 08:12:21 2018 +0100
Committer: Gordon Sim <gsim@redhat.com>
Committed: Wed Aug 8 08:12:21 2018 +0100

----------------------------------------------------------------------
 src/qpid/client/ConnectionHandler.cpp       | 11 ++++++++++-
 src/qpid/client/ConnectionSettings.cpp      |  3 ++-
 src/qpid/client/ConnectionSettings.h        |  6 ++++++
 src/qpid/client/amqp0_10/ConnectionImpl.cpp |  2 ++
 4 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/5aa10809/src/qpid/client/ConnectionHandler.cpp
----------------------------------------------------------------------
diff --git a/src/qpid/client/ConnectionHandler.cpp b/src/qpid/client/ConnectionHandler.cpp
index 77d43f1..4f044c2 100644
--- a/src/qpid/client/ConnectionHandler.cpp
+++ b/src/qpid/client/ConnectionHandler.cpp
@@ -148,7 +148,16 @@ void ConnectionHandler::outgoing(AMQFrame& frame)
 
 void ConnectionHandler::waitForOpen()
 {
-    waitFor(ESTABLISHED);
+    if (ConnectionSettings::connectTimeout) {
+        if (!waitFor(ESTABLISHED, qpid::sys::Duration(ConnectionSettings::connectTimeout
* qpid::sys::TIME_SEC))) {
+            errorText = "Connection open timed out";
+            QPID_LOG(warning, errorText);
+            setState(FAILED);
+        }
+    } else {
+        waitFor(ESTABLISHED);//ESTABLISHED = OPEN, CLOSED or FAILED
+    }
+
     if (getState() == FAILED) {
         throw TransportFailure(errorText);
     } else if (getState() == CLOSED) {

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/5aa10809/src/qpid/client/ConnectionSettings.cpp
----------------------------------------------------------------------
diff --git a/src/qpid/client/ConnectionSettings.cpp b/src/qpid/client/ConnectionSettings.cpp
index 3bfde06..32e3e95 100644
--- a/src/qpid/client/ConnectionSettings.cpp
+++ b/src/qpid/client/ConnectionSettings.cpp
@@ -42,7 +42,8 @@ ConnectionSettings::ConnectionSettings() :
     minSsf(0),
     maxSsf(256),
     sslCertName(""),
-    sslIgnoreHostnameVerificationFailure(false)
+    sslIgnoreHostnameVerificationFailure(false),
+    connectTimeout(0)
 {}
 
 ConnectionSettings::~ConnectionSettings() {}

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/5aa10809/src/qpid/client/ConnectionSettings.h
----------------------------------------------------------------------
diff --git a/src/qpid/client/ConnectionSettings.h b/src/qpid/client/ConnectionSettings.h
index a4b2b59..2530042 100644
--- a/src/qpid/client/ConnectionSettings.h
+++ b/src/qpid/client/ConnectionSettings.h
@@ -138,6 +138,12 @@ struct QPID_CLIENT_CLASS_EXTERN ConnectionSettings {
      * If using SSL, connect regardless of hostname verification failure.
      */
     bool sslIgnoreHostnameVerificationFailure;
+
+    /**
+     * Timeout period (in seconds) to wait for a connection to broker to open.
+     * 0 means wait forever.
+     */
+    uint16_t connectTimeout;
 };
 
 }} // namespace qpid::client

http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/5aa10809/src/qpid/client/amqp0_10/ConnectionImpl.cpp
----------------------------------------------------------------------
diff --git a/src/qpid/client/amqp0_10/ConnectionImpl.cpp b/src/qpid/client/amqp0_10/ConnectionImpl.cpp
index d86a923..e49ecb7 100644
--- a/src/qpid/client/amqp0_10/ConnectionImpl.cpp
+++ b/src/qpid/client/amqp0_10/ConnectionImpl.cpp
@@ -193,6 +193,8 @@ void ConnectionImpl::setOption(const std::string& name, const Variant&
value)
         disableAutoDecode = value;
     } else if (name == "virtualhost") {
         settings.virtualhost = value.asString();
+    } else if (name == "connect-timeout" || name == "connect_timeout") {
+        settings.connectTimeout = value; 
     } else {
         throw qpid::messaging::MessagingException(QPID_MSG("Invalid option: " << name
<< " not recognised"));
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message