diff options
| author | Gordon Sim <gsim@apache.org> | 2007-09-26 10:51:12 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2007-09-26 10:51:12 +0000 |
| commit | 5426e8284e8f7e1454a8cb0462b91c6c60c722bc (patch) | |
| tree | c761f3c96653b748e16b89c227e1fee69ef5a6ee /cpp/src | |
| parent | 5af56efd2ca4ced3a95f9f0343a9ad8851dc6af5 (diff) | |
| download | qpid-python-5426e8284e8f7e1454a8cb0462b91c6c60c722bc.tar.gz | |
Detect that connection is already closed on attempt to close()
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@579582 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
| -rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.cpp | 3 | ||||
| -rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.cpp | 10 | ||||
| -rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.h | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp index 40e13593ea..4058bfb33f 100644 --- a/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/cpp/src/qpid/client/ConnectionHandler.cpp @@ -102,6 +102,9 @@ void ConnectionHandler::waitForOpen() void ConnectionHandler::close() { + if (getState() != OPEN) { + throw Exception("Connection not open"); + } setState(CLOSING); send(ConnectionCloseBody(version, 200, OK, 0, 0)); waitFor(CLOSED); diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index d21d550ee2..8ab60cff50 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -26,7 +26,7 @@ using namespace qpid::client; using namespace qpid::framing; using namespace qpid::sys; -ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) : connector(c) +ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) : connector(c), isClosed(false) { handler.in = boost::bind(&ConnectionImpl::incoming, this, _1); handler.out = boost::bind(&Connector::send, connector, _1); @@ -81,6 +81,7 @@ void ConnectionImpl::open(const std::string& host, int port, void ConnectionImpl::close() { + assertNotClosed(); handler.close(); } @@ -120,6 +121,7 @@ void ConnectionImpl::signalClose(uint16_t code, const std::string& text) i->second->closed(code, text); } sessions.clear(); + isClosed = true; } SessionCore::shared_ptr ConnectionImpl::find(uint16_t id) @@ -131,3 +133,9 @@ SessionCore::shared_ptr ConnectionImpl::find(uint16_t id) } return i->second; } + +void ConnectionImpl::assertNotClosed() +{ + Mutex::ScopedLock l(lock); + if (isClosed) throw Exception("Connection has been closed"); +} diff --git a/cpp/src/qpid/client/ConnectionImpl.h b/cpp/src/qpid/client/ConnectionImpl.h index a2ee14ea6e..fc786ba643 100644 --- a/cpp/src/qpid/client/ConnectionImpl.h +++ b/cpp/src/qpid/client/ConnectionImpl.h @@ -46,6 +46,7 @@ class ConnectionImpl : public framing::FrameHandler, boost::shared_ptr<Connector> connector; framing::ProtocolVersion version; sys::Mutex lock; + bool isClosed; void incoming(framing::AMQFrame& frame); void closed(); @@ -54,6 +55,7 @@ class ConnectionImpl : public framing::FrameHandler, void idleIn(); void shutdown(); void signalClose(uint16_t, const std::string&); + void assertNotClosed(); SessionCore::shared_ptr find(uint16_t); public: |
