summaryrefslogtreecommitdiff
path: root/qpid/cpp/src
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2008-06-26 12:25:58 +0000
committerGordon Sim <gsim@apache.org>2008-06-26 12:25:58 +0000
commit2a669d697451b965e70f562ed8b66cd1eee38446 (patch)
tree768bdbc6c61228c7cf2582ecff05948eac47f4ec /qpid/cpp/src
parent20d9a6bca22d84364098a3258c305d9fe5d906b5 (diff)
downloadqpid-python-2a669d697451b965e70f562ed8b66cd1eee38446.tar.gz
QPID-1137: don't treat connection as opened if the open never succeeds
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@671877 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src')
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionImpl.cpp12
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionImpl.h2
-rw-r--r--qpid/cpp/src/tests/ClientSessionTest.cpp15
3 files changed, 26 insertions, 3 deletions
diff --git a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
index 22f10d3620..6dca4dcf21 100644
--- a/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
+++ b/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
@@ -40,7 +40,7 @@ ConnectionImpl::ConnectionImpl(framing::ProtocolVersion v, const ConnectionSetti
handler(settings, v),
connector(v, settings, this),
version(v),
- isClosed(false),
+ isClosed(true),//closed until successfully opened
isClosing(false)
{
QPID_LOG(debug, "ConnectionImpl created for " << version);
@@ -88,12 +88,20 @@ void ConnectionImpl::incoming(framing::AMQFrame& frame)
s->in(frame);
}
+bool ConnectionImpl::isOpen() const
+{
+ return !isClosed && !isClosing;
+}
+
+
void ConnectionImpl::open(const std::string& host, int port)
{
QPID_LOG(info, "Connecting to " << host << ":" << port);
connector.connect(host, port);
connector.init();
- handler.waitForOpen();
+ handler.waitForOpen();
+ Mutex::ScopedLock l(lock);
+ isClosed = false;
}
void ConnectionImpl::idleIn()
diff --git a/qpid/cpp/src/qpid/client/ConnectionImpl.h b/qpid/cpp/src/qpid/client/ConnectionImpl.h
index 089e73335d..b02dda5af7 100644
--- a/qpid/cpp/src/qpid/client/ConnectionImpl.h
+++ b/qpid/cpp/src/qpid/client/ConnectionImpl.h
@@ -72,7 +72,7 @@ class ConnectionImpl : public Bounds,
~ConnectionImpl();
void open(const std::string& host, int port);
- bool isOpen() const { return !isClosed && !isClosing; }
+ bool isOpen() const;
void addSession(const boost::shared_ptr<SessionImpl>&);
diff --git a/qpid/cpp/src/tests/ClientSessionTest.cpp b/qpid/cpp/src/tests/ClientSessionTest.cpp
index 0475350d6a..505f3248a4 100644
--- a/qpid/cpp/src/tests/ClientSessionTest.cpp
+++ b/qpid/cpp/src/tests/ClientSessionTest.cpp
@@ -246,6 +246,21 @@ QPID_AUTO_TEST_CASE(testGet) {
BOOST_CHECK_EQUAL("foo1", fix.subs.get("getq").getData());
}
+QPID_AUTO_TEST_CASE(testOpenFailure) {
+ BrokerFixture b;
+ Connection c;
+ string host("unknowable-host");
+ try {
+ c.open(host);
+ } catch (const Exception&) {
+ BOOST_CHECK(!c.isOpen());
+ }
+ b.open(c);
+ BOOST_CHECK(c.isOpen());
+ c.close();
+ BOOST_CHECK(!c.isOpen());
+}
+
QPID_AUTO_TEST_SUITE_END()