summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/client
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2009-03-09 16:58:16 +0000
committerAndrew Stitcher <astitcher@apache.org>2009-03-09 16:58:16 +0000
commitbbbd455d8053d3fea713d8f04b0187ac73c72d83 (patch)
tree5d1cb6b2c00e09800d179b8524224025b842dd7d /cpp/src/qpid/client
parent0a2f3270e0a51ab46ce29536fd8a15bdbc236c73 (diff)
downloadqpid-python-bbbd455d8053d3fea713d8f04b0187ac73c72d83.tar.gz
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
Diffstat (limited to 'cpp/src/qpid/client')
-rw-r--r--cpp/src/qpid/client/Connector.cpp37
1 files changed, 19 insertions, 18 deletions
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() {