From 2b8e82875776feb8393c7791975acc9cf9fdb5e1 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Tue, 22 Apr 2008 10:33:12 +0000 Subject: QPID-648: (based on patch from mfarrellee@redhat.com) * apply authentication to final 0-10 codepath * consolidate conditional compilation of sasl-related code * improved handling of connection close during connection establishment in client git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@650439 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/ConnectionHandler.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cpp/src/qpid/client/ConnectionHandler.cpp') diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp index 13de271e3b..83cc357ded 100644 --- a/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/cpp/src/qpid/client/ConnectionHandler.cpp @@ -42,7 +42,7 @@ const std::string INVALID_STATE_CLOSE_OK("close-ok received in invalid state"); } ConnectionHandler::ConnectionHandler() - : StateManager(NOT_STARTED), outHandler(*this), proxy(outHandler) + : StateManager(NOT_STARTED), outHandler(*this), proxy(outHandler), errorCode(200) { mechanism = PLAIN; @@ -54,6 +54,7 @@ ConnectionHandler::ConnectionHandler() version = framing::highestProtocolVersion; ESTABLISHED.insert(FAILED); + ESTABLISHED.insert(CLOSED); ESTABLISHED.insert(OPEN); } @@ -98,8 +99,8 @@ void ConnectionHandler::outgoing(AMQFrame& frame) void ConnectionHandler::waitForOpen() { waitFor(ESTABLISHED); - if (getState() == FAILED) { - throw Exception("Failed to establish connection."); + if (getState() == FAILED || getState() == CLOSED) { + throw ConnectionException(errorCode, errorText); } } @@ -108,7 +109,7 @@ void ConnectionHandler::close() switch (getState()) { case NEGOTIATING: case OPENING: - setState(FAILED); + fail("Connection closed before it was established"); break; case OPEN: setState(CLOSING); @@ -128,6 +129,8 @@ void ConnectionHandler::checkState(STATES s, const std::string& msg) void ConnectionHandler::fail(const std::string& message) { + errorCode = 502; + errorText = message; QPID_LOG(warning, message); setState(FAILED); } @@ -172,6 +175,8 @@ void ConnectionHandler::close(uint16_t replyCode, const std::string& replyText) { proxy.closeOk(); setState(CLOSED); + errorCode = replyCode; + errorText = replyText; QPID_LOG(warning, "Broker closed connection: " << replyCode << ", " << replyText); if (onError) { onError(replyCode, replyText); -- cgit v1.2.1