summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-09-28 17:53:16 +0000
committerAlan Conway <aconway@apache.org>2007-09-28 17:53:16 +0000
commit68c4615c9f0c37d3debfdace0c2169103cf9287d (patch)
tree0217ca70a9acf96c810fc15ab888b56e888ca8d6 /cpp/src
parent28b72367e7d93d51c34adf2e7a59da21b20e694d (diff)
downloadqpid-python-68c4615c9f0c37d3debfdace0c2169103cf9287d.tar.gz
Ensure no danbling pointers in client API:
- Session -shared_ptr-> SessionCore -shared_ptr-> ConnectionImpl - Connection -shared_ptr-> ConnectionImpl - ConnectionImpl -weak_ptr-> SessionCore git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@580440 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/client/Completion.h4
-rw-r--r--cpp/src/qpid/client/Connection.cpp4
-rw-r--r--cpp/src/qpid/client/Connection.h2
-rw-r--r--cpp/src/qpid/client/ConnectionImpl.cpp10
-rw-r--r--cpp/src/qpid/client/ConnectionImpl.h3
-rw-r--r--cpp/src/qpid/client/Response.h2
-rw-r--r--cpp/src/qpid/client/SessionCore.cpp16
-rw-r--r--cpp/src/qpid/client/SessionCore.h8
-rw-r--r--cpp/src/qpid/client/TypedResult.h2
9 files changed, 29 insertions, 22 deletions
diff --git a/cpp/src/qpid/client/Completion.h b/cpp/src/qpid/client/Completion.h
index 68cff3f11a..a126bc9766 100644
--- a/cpp/src/qpid/client/Completion.h
+++ b/cpp/src/qpid/client/Completion.h
@@ -33,10 +33,10 @@ class Completion
{
protected:
Future future;
- SessionCore::shared_ptr session;
+ shared_ptr<SessionCore> session;
public:
- Completion(Future f, SessionCore::shared_ptr s) : future(f), session(s) {}
+ Completion(Future f, shared_ptr<SessionCore> s) : future(f), session(s) {}
void sync()
{
diff --git a/cpp/src/qpid/client/Connection.cpp b/cpp/src/qpid/client/Connection.cpp
index 2d8cbb2ddb..0a6a88ae90 100644
--- a/cpp/src/qpid/client/Connection.cpp
+++ b/cpp/src/qpid/client/Connection.cpp
@@ -72,7 +72,7 @@ void Connection::openChannel(Channel& channel) {
Session Connection::newSession(uint32_t detachedLifetime) {
shared_ptr<SessionCore> core(
- new SessionCore(*impl, ++channelIdCounter, max_frame_size));
+ new SessionCore(impl, ++channelIdCounter, max_frame_size));
impl->addSession(core);
core->open(detachedLifetime);
return Session(core);
@@ -82,7 +82,7 @@ void Connection::resume(Session& session) {
shared_ptr<SessionCore> core=session.impl;
core->setChannel(++channelIdCounter);
impl->addSession(core);
- core->resume(*impl);
+ core->resume(impl);
}
void Connection::close() {
diff --git a/cpp/src/qpid/client/Connection.h b/cpp/src/qpid/client/Connection.h
index 4a9a68e8b3..2e5059f135 100644
--- a/cpp/src/qpid/client/Connection.h
+++ b/cpp/src/qpid/client/Connection.h
@@ -57,7 +57,7 @@ class Connection
framing::ChannelId channelIdCounter;
framing::ProtocolVersion version;
const uint32_t max_frame_size;
- ConnectionImpl::shared_ptr impl;
+ shared_ptr<ConnectionImpl> impl;
bool isOpen;
bool debug;
diff --git a/cpp/src/qpid/client/ConnectionImpl.cpp b/cpp/src/qpid/client/ConnectionImpl.cpp
index 43576d2273..fae93e8294 100644
--- a/cpp/src/qpid/client/ConnectionImpl.cpp
+++ b/cpp/src/qpid/client/ConnectionImpl.cpp
@@ -45,8 +45,8 @@ ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c)
void ConnectionImpl::addSession(const boost::shared_ptr<SessionCore>& session)
{
Mutex::ScopedLock l(lock);
- boost::shared_ptr<SessionCore>& s = sessions[session->getChannel()];
- if (s)
+ boost::weak_ptr<SessionCore>& s = sessions[session->getChannel()];
+ if (s.lock())
throw ChannelBusyException();
s = session;
}
@@ -61,7 +61,7 @@ void ConnectionImpl::incoming(framing::AMQFrame& frame)
boost::shared_ptr<SessionCore> s;
{
Mutex::ScopedLock l(lock);
- s = sessions[frame.getChannel()];
+ s = sessions[frame.getChannel()].lock();
}
if (!s)
throw ChannelErrorException();
@@ -120,7 +120,9 @@ void ConnectionImpl::signalClose(uint16_t code, const std::string& text)
{
Mutex::ScopedLock l(lock);
for (SessionMap::iterator i = sessions.begin(); i != sessions.end(); i++) {
- i->second->closed(code, text);
+ boost::shared_ptr<SessionCore> s = i->second.lock();
+ if (s)
+ s->closed(code, text);
}
sessions.clear();
isClosed = true;
diff --git a/cpp/src/qpid/client/ConnectionImpl.h b/cpp/src/qpid/client/ConnectionImpl.h
index 975beaa101..f20534f1aa 100644
--- a/cpp/src/qpid/client/ConnectionImpl.h
+++ b/cpp/src/qpid/client/ConnectionImpl.h
@@ -24,6 +24,7 @@
#include <map>
#include <boost/shared_ptr.hpp>
+#include <boost/weak_ptr.hpp>
#include "qpid/framing/FrameHandler.h"
#include "qpid/sys/Mutex.h"
#include "qpid/sys/ShutdownHandler.h"
@@ -41,7 +42,7 @@ class ConnectionImpl : public framing::FrameHandler,
public sys::ShutdownHandler
{
- typedef std::map<uint16_t, boost::shared_ptr<SessionCore> > SessionMap;
+ typedef std::map<uint16_t, boost::weak_ptr<SessionCore> > SessionMap;
SessionMap sessions;
ConnectionHandler handler;
boost::shared_ptr<Connector> connector;
diff --git a/cpp/src/qpid/client/Response.h b/cpp/src/qpid/client/Response.h
index f9a9f97b75..2b7d55ec1f 100644
--- a/cpp/src/qpid/client/Response.h
+++ b/cpp/src/qpid/client/Response.h
@@ -32,7 +32,7 @@ namespace client {
class Response : public Completion
{
public:
- Response(Future f, SessionCore::shared_ptr s) : Completion(f, s) {}
+ Response(Future f, shared_ptr<SessionCore> s) : Completion(f, s) {}
template <class T> T& as()
{
diff --git a/cpp/src/qpid/client/SessionCore.cpp b/cpp/src/qpid/client/SessionCore.cpp
index 3f8f9244ef..966d07eaef 100644
--- a/cpp/src/qpid/client/SessionCore.cpp
+++ b/cpp/src/qpid/client/SessionCore.cpp
@@ -20,22 +20,25 @@
*/
#include "SessionCore.h"
-#include "qpid/framing/constants.h"
#include "Future.h"
#include "FutureResponse.h"
#include "FutureResult.h"
+#include "ConnectionImpl.h"
+
+#include "qpid/framing/constants.h"
#include <boost/bind.hpp>
using namespace qpid::client;
using namespace qpid::framing;
-SessionCore::SessionCore(FrameHandler& out_, uint16_t ch, uint64_t maxFrameSize)
- : channel(ch), l2(*this), l3(maxFrameSize), uuid(false), sync(false)
+SessionCore::SessionCore(shared_ptr<ConnectionImpl> conn, uint16_t ch, uint64_t maxFrameSize)
+ : connection(conn), channel(ch), l2(*this), l3(maxFrameSize),
+ uuid(false), sync(false)
{
l2.next = &l3;
l3.out = &out;
- out.next = &out_;
+ out.next = connection.get();
}
SessionCore::~SessionCore() {}
@@ -108,8 +111,9 @@ void SessionCore::open(uint32_t detachedLifetime) {
l2.open(detachedLifetime);
}
-void SessionCore::resume(FrameHandler& out_) {
- out.next = &out_;
+void SessionCore::resume(shared_ptr<ConnectionImpl> conn) {
+ connection = conn;
+ out.next = connection.get();
l2.resume();
}
diff --git a/cpp/src/qpid/client/SessionCore.h b/cpp/src/qpid/client/SessionCore.h
index b717914206..74b15a11da 100644
--- a/cpp/src/qpid/client/SessionCore.h
+++ b/cpp/src/qpid/client/SessionCore.h
@@ -36,6 +36,7 @@ namespace qpid {
namespace client {
class Future;
+class ConnectionImpl;
/**
* Session implementation, sets up handler chains.
@@ -50,6 +51,7 @@ class SessionCore : public framing::FrameHandler::InOutHandler
std::string text;
};
+ shared_ptr<ConnectionImpl> connection;
uint16_t channel;
SessionHandler l2;
ExecutionHandler l3;
@@ -62,9 +64,7 @@ class SessionCore : public framing::FrameHandler::InOutHandler
void handleOut(framing::AMQFrame& frame);
public:
- typedef shared_ptr<SessionCore> shared_ptr;
-
- SessionCore(framing::FrameHandler& out, uint16_t channel, uint64_t maxFrameSize);
+ SessionCore(shared_ptr<ConnectionImpl>, uint16_t channel, uint64_t maxFrameSize);
~SessionCore();
framing::FrameSet::shared_ptr get();
@@ -83,7 +83,7 @@ class SessionCore : public framing::FrameHandler::InOutHandler
/** Closed by peer */
void closed(uint16_t code, const std::string& text);
- void resume(framing::FrameHandler& out);
+ void resume(shared_ptr<ConnectionImpl>);
void suspend();
void setSync(bool);
diff --git a/cpp/src/qpid/client/TypedResult.h b/cpp/src/qpid/client/TypedResult.h
index 38892c42bd..edcf728c54 100644
--- a/cpp/src/qpid/client/TypedResult.h
+++ b/cpp/src/qpid/client/TypedResult.h
@@ -33,7 +33,7 @@ template <class T> class TypedResult : public Completion
bool decoded;
public:
- TypedResult(Future f, SessionCore::shared_ptr s) : Completion(f, s), decoded(false) {}
+ TypedResult(Future f, shared_ptr<SessionCore> s) : Completion(f, s), decoded(false) {}
T& get()
{