Author: astitcher Date: Mon Mar 9 16:58:16 2009 New Revision: 751751 URL: http://svn.apache.org/viewvc?rev=751751&view=rev Log: Close a potential race between closing a connection and sending data
Modified: qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Modified: qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?rev=751751&r1=751750&r2=751751&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Mon Mar 9 16:58:16 2009 @@ -216,18 +216,21 @@ } 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 @@ } 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() { --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org