From bbbd455d8053d3fea713d8f04b0187ac73c72d83 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 9 Mar 2009 16:58:16 +0000 Subject: Close a potential race between closing a connection and sending data git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@751751 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/Connector.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/qpid/client/Connector.cpp b/cpp/src/qpid/client/Connector.cpp index 1d1e39cd10..bf1627bbff 100644 --- a/cpp/src/qpid/client/Connector.cpp +++ b/cpp/src/qpid/client/Connector.cpp @@ -216,18 +216,21 @@ void TCPConnector::init(){ } bool TCPConnector::closeInternal() { + bool ret; + { Mutex::ScopedLock l(closedLock); - bool ret = !closed; + ret = !closed; if (!closed) { closed = true; aio->queueForDeletion(); poller->shutdown(); } - if (!joined && receiver.id() != Thread::current().id()) { - joined = true; - Mutex::ScopedUnlock u(closedLock); - receiver.join(); + if (joined || receiver.id() == Thread::current().id()) { + return ret; + } + joined = true; } + receiver.join(); return ret; } @@ -260,21 +263,19 @@ const std::string& TCPConnector::getIdentifier() const { } void TCPConnector::send(AMQFrame& frame) { + Mutex::ScopedLock l(lock); + frames.push_back(frame); + //only ask to write if this is the end of a frameset or if we + //already have a buffers worth of data + currentSize += frame.encodedSize(); bool notifyWrite = false; - { - Mutex::ScopedLock l(lock); - frames.push_back(frame); - //only ask to write if this is the end of a frameset or if we - //already have a buffers worth of data - currentSize += frame.encodedSize(); - if (frame.getEof()) { - lastEof = frames.size(); - notifyWrite = true; - } else { - notifyWrite = (currentSize >= maxFrameSize); - } + if (frame.getEof()) { + lastEof = frames.size(); + notifyWrite = true; + } else { + notifyWrite = (currentSize >= maxFrameSize); } - if (notifyWrite) aio->notifyPendingWrite(); + if (notifyWrite && !closed) aio->notifyPendingWrite(); } void TCPConnector::handleClosed() { -- cgit v1.2.1