diff options
author | Andrew Stitcher <astitcher@apache.org> | 2008-07-24 04:42:51 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2008-07-24 04:42:51 +0000 |
commit | 3e0f90a2ac7d708ef693a255a9ed4feafffb2131 (patch) | |
tree | 5588d53e47269a81a3b1181be02da9929faf1321 /cpp/src | |
parent | 2fc957e3d28fa3b084ef334b702bb5116f60c462 (diff) | |
download | qpid-python-3e0f90a2ac7d708ef693a255a9ed4feafffb2131.tar.gz |
Refactor to change client connector state machine to be held in ConnectionHandler
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@679268 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.cpp | 11 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionHandler.h | 4 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.cpp | 20 | ||||
-rw-r--r-- | cpp/src/qpid/client/ConnectionImpl.h | 3 |
4 files changed, 20 insertions, 18 deletions
diff --git a/cpp/src/qpid/client/ConnectionHandler.cpp b/cpp/src/qpid/client/ConnectionHandler.cpp index 05f6bb9733..22ebec76bf 100644 --- a/cpp/src/qpid/client/ConnectionHandler.cpp +++ b/cpp/src/qpid/client/ConnectionHandler.cpp @@ -186,3 +186,14 @@ void ConnectionHandler::closeOk() } setState(CLOSED); } + +bool ConnectionHandler::isOpen() const +{ + return getState() == OPEN; +} + +bool ConnectionHandler::isClosed() const +{ + int s = getState(); + return s == CLOSING || s == CLOSED || s == FAILED; +} diff --git a/cpp/src/qpid/client/ConnectionHandler.h b/cpp/src/qpid/client/ConnectionHandler.h index 1cf0c905ed..f8bd5e5d49 100644 --- a/cpp/src/qpid/client/ConnectionHandler.h +++ b/cpp/src/qpid/client/ConnectionHandler.h @@ -96,6 +96,10 @@ public: void close(); void fail(const std::string& message); + // Note that open and closed aren't related by open = !closed + bool isOpen() const; + bool isClosed() const; + CloseListener onClose; ErrorListener onError; }; diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp index f32e21c389..e094e13fff 100644 --- a/cpp/src/qpid/client/ConnectionImpl.cpp +++ b/cpp/src/qpid/client/ConnectionImpl.cpp @@ -40,9 +40,7 @@ ConnectionImpl::ConnectionImpl(framing::ProtocolVersion v, const ConnectionSetti : Bounds(settings.maxFrameSize * settings.bounds), handler(settings, v), connector(new Connector(v, settings, this)), - version(v), - isClosed(true),//closed until successfully opened - isClosing(false) + version(v) { QPID_LOG(debug, "ConnectionImpl created for " << version); handler.in = boost::bind(&ConnectionImpl::incoming, this, _1); @@ -91,7 +89,7 @@ void ConnectionImpl::incoming(framing::AMQFrame& frame) bool ConnectionImpl::isOpen() const { - return !isClosed && !isClosing; + return handler.isOpen(); } @@ -101,8 +99,6 @@ void ConnectionImpl::open(const std::string& host, int port) connector->connect(host, port); connector->init(); handler.waitForOpen(); - Mutex::ScopedLock l(lock); - isClosed = false; } void ConnectionImpl::idleIn() @@ -118,19 +114,13 @@ void ConnectionImpl::idleOut() void ConnectionImpl::close() { - Mutex::ScopedLock l(lock); - if (isClosing || isClosed) return; - isClosing = true; - { - Mutex::ScopedUnlock u(lock); - handler.close(); - } + if (!handler.isOpen()) return; + handler.close(); closed(NORMAL, "Closed by client"); } template <class F> void ConnectionImpl::closeInternal(const F& f) { - isClosed = true; connector->close(); for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); ++i) { boost::shared_ptr<SessionImpl> s = i->second.lock(); @@ -151,7 +141,7 @@ void ConnectionImpl::shutdown() { Mutex::ScopedLock l(lock); // FIXME aconway 2008-06-06: exception use, connection-forced is incorrect here. setException(new ConnectionException(CONNECTION_FORCED, CONN_CLOSED)); - if (isClosed) return; + if (handler.isClosed()) return; handler.fail(CONN_CLOSED); closeInternal(boost::bind(&SessionImpl::connectionBroke, _1, CONNECTION_FORCED, CONN_CLOSED)); } diff --git a/cpp/src/qpid/client/ConnectionImpl.h b/cpp/src/qpid/client/ConnectionImpl.h index 98fb212c3e..cd0788d68b 100644 --- a/cpp/src/qpid/client/ConnectionImpl.h +++ b/cpp/src/qpid/client/ConnectionImpl.h @@ -56,8 +56,6 @@ class ConnectionImpl : public Bounds, boost::scoped_ptr<Connector> connector; framing::ProtocolVersion version; sys::Mutex lock; - bool isClosed; - bool isClosing; template <class F> void closeInternal(const F&); @@ -66,7 +64,6 @@ class ConnectionImpl : public Bounds, void idleOut(); void idleIn(); void shutdown(); - bool setClosing(); public: ConnectionImpl(framing::ProtocolVersion version, const ConnectionSettings& settings); |