diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.cpp | 16 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.cpp | 1 |
2 files changed, 12 insertions, 5 deletions
diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp index cbdeff9cff..df84a98811 100644 --- a/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/cpp/src/qpid/client/ConnectionHandler.cpp @@ -102,12 +102,18 @@ void ConnectionHandler::waitForOpen() void ConnectionHandler::close() { - if (getState() != OPEN) { - throw Exception("Connection not open"); + switch (getState()) { + case NEGOTIATING: + case OPENING: + setState(FAILED); + break; + case OPEN: + setState(CLOSING); + send(ConnectionCloseBody(version, 200, OK, 0, 0)); + waitFor(CLOSED); + break; + // Nothing to do for CLOSING, CLOSED, FAILED or NOT_STARTED } - setState(CLOSING); - send(ConnectionCloseBody(version, 200, OK, 0, 0)); - waitFor(CLOSED); } void ConnectionHandler::send(const framing::AMQBody& body) diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index cf00b2b296..ea467429a1 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -88,6 +88,7 @@ void ConnectionImpl::open(const std::string& host, int port, void ConnectionImpl::close() { + Mutex::ScopedLock l(lock); if (!isClosed) handler.close(); } |