summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2009-08-13 07:47:43 +0000
committerGordon Sim <gsim@apache.org>2009-08-13 07:47:43 +0000
commit7b0bd771eb77aa60b25879770333e56c64d76ee3 (patch)
treec122b581d930bd6673feeb9ed8d7d2bbadda9e69
parentc22dd58dd09c72a83867a9b3ec833caaf2ee8d3a (diff)
downloadqpid-python-7b0bd771eb77aa60b25879770333e56c64d76ee3.tar.gz
QPID-2048: Handle connection fail while attempting to close.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@803802 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionHandler.cpp12
-rw-r--r--qpid/cpp/src/qpid/client/StateManager.cpp12
-rw-r--r--qpid/cpp/src/qpid/client/StateManager.h1
3 files changed, 21 insertions, 4 deletions
diff --git a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
index 3d338af920..9b2f662c8e 100644
--- a/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
+++ b/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
@@ -147,11 +147,15 @@ void ConnectionHandler::close()
fail("Connection closed before it was established");
break;
case OPEN:
- setState(CLOSING);
- proxy.close(200, OK);
- waitFor(FINISHED);
+ if (setState(CLOSING, OPEN)) {
+ proxy.close(200, OK);
+ waitFor(FINISHED);//FINISHED = CLOSED or FAILED
+ }
+ //else, state was changed from open after we checked, can only
+ //change to failed or closed, so nothing to do
break;
- // Nothing to do for CLOSING, CLOSED, FAILED or NOT_STARTED
+
+ // Nothing to do if already CLOSING, CLOSED, FAILED or if NOT_STARTED
}
}
diff --git a/qpid/cpp/src/qpid/client/StateManager.cpp b/qpid/cpp/src/qpid/client/StateManager.cpp
index 9239950a3f..5462e0fed4 100644
--- a/qpid/cpp/src/qpid/client/StateManager.cpp
+++ b/qpid/cpp/src/qpid/client/StateManager.cpp
@@ -60,6 +60,18 @@ void StateManager::setState(int s)
stateLock.notifyAll();
}
+bool StateManager::setState(int s, int expected)
+{
+ Monitor::ScopedLock l(stateLock);
+ if (state == expected) {
+ state = s;
+ stateLock.notifyAll();
+ return true;
+ } else {
+ return false;
+ }
+}
+
int StateManager::getState() const
{
Monitor::ScopedLock l(stateLock);
diff --git a/qpid/cpp/src/qpid/client/StateManager.h b/qpid/cpp/src/qpid/client/StateManager.h
index b01664a0c1..3c8412dfa7 100644
--- a/qpid/cpp/src/qpid/client/StateManager.h
+++ b/qpid/cpp/src/qpid/client/StateManager.h
@@ -36,6 +36,7 @@ class StateManager
public:
StateManager(int initial);
void setState(int state);
+ bool setState(int state, int expected);
int getState() const ;
void waitForStateChange(int current);
void waitFor(std::set<int> states);