From 0bd360825f729510866f9366630e813dffdb7d75 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 15 Jun 2011 18:15:56 +0000 Subject: QPID-3129: cluster_tests.LongTests.test_failover hangs. Fixed a bug in ConnectionImpl: at each failover udpate the client was appending rather than merging the new broker addresses so failover took longer & longer. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1136138 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'cpp') diff --git a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp index 345534b1c2..473f5ecd1c 100644 --- a/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp @@ -40,11 +40,15 @@ using qpid::types::VAR_LIST; using qpid::framing::Uuid; namespace { -void convert(const Variant::List& from, std::vector& to) +void merge(const std::string& value, std::vector& list) { + if (std::find(list.begin(), list.end(), value) == list.end()) + list.push_back(value); +} + +void merge(const Variant::List& from, std::vector& to) { - for (Variant::List::const_iterator i = from.begin(); i != from.end(); ++i) { - to.push_back(i->asString()); - } + for (Variant::List::const_iterator i = from.begin(); i != from.end(); ++i) + merge(i->asString(), to); } std::string asString(const std::vector& v) { @@ -93,9 +97,9 @@ void ConnectionImpl::setOption(const std::string& name, const Variant& value) maxReconnectInterval = value; } else if (name == "reconnect-urls" || name == "reconnect_urls") { if (value.getType() == VAR_LIST) { - convert(value.asList(), urls); + merge(value.asList(), urls); } else { - urls.push_back(value.asString()); + merge(value.asString(), urls); } } else if (name == "username") { settings.username = value.asString(); @@ -255,14 +259,9 @@ void ConnectionImpl::connect(const qpid::sys::AbsTime& started) } void ConnectionImpl::mergeUrls(const std::vector& more, const sys::Mutex::ScopedLock&) { - if (more.size()) { - for (size_t i = 0; i < more.size(); ++i) { - if (std::find(urls.begin(), urls.end(), more[i].str()) == urls.end()) { - urls.push_back(more[i].str()); - } - } - QPID_LOG(debug, "Added known-hosts, reconnect-urls=" << asString(urls)); - } + for (std::vector::const_iterator i = more.begin(); i != more.end(); ++i) + merge(i->str(), urls); + QPID_LOG(debug, "Added known-hosts, reconnect-urls=" << asString(urls)); } bool ConnectionImpl::tryConnect() -- cgit v1.2.1