diff options
author | Gordon Sim <gsim@apache.org> | 2007-04-16 11:32:43 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2007-04-16 11:32:43 +0000 |
commit | 1632488ab1ff6270b4ef37974b5de2b422365bdb (patch) | |
tree | e2e4255e3e42eb5f61ca6988d0f11e68f6befee4 /cpp/src/qpid/client/ClientConnection.cpp | |
parent | fb707cada1bc9c4372d9568d4dd16b511178a958 (diff) | |
download | qpid-python-1632488ab1ff6270b4ef37974b5de2b422365bdb.tar.gz |
Fixes QPID-303 and QPID-409.
* qpid/client/Connector: atomic test-and-set for closed, don't try to close if already closed
* qpid/client/Connection: atomic test-and-set for isOpen, don't send requests to broker on shutdown
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@529209 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/client/ClientConnection.cpp')
-rw-r--r-- | cpp/src/qpid/client/ClientConnection.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/cpp/src/qpid/client/ClientConnection.cpp b/cpp/src/qpid/client/ClientConnection.cpp index 48616cf3d9..177c9c4b73 100644 --- a/cpp/src/qpid/client/ClientConnection.cpp +++ b/cpp/src/qpid/client/ClientConnection.cpp @@ -75,30 +75,49 @@ void Connection::open( } void Connection::shutdown() { - close(); + //this indicates that the socket to the server has closed we do + //not want to send a close request (or any other requests) + if(markClosed()) { + std::cout << "Connection to peer closed!" << std::endl; + closeChannels(); + } } void Connection::close( ReplyCode code, const string& msg, ClassId classId, MethodId methodId ) { - if(isOpen) { + if(markClosed()) { // TODO aconway 2007-01-29: Exception handling - could end up // partly closed with threads left unjoined. - isOpen = false; channel0.sendAndReceive<ConnectionCloseOkBody>( make_shared_ptr(new ConnectionCloseBody( - getVersion(), code, msg, classId, methodId))); - - using boost::bind; - for_each(channels.begin(), channels.end(), - bind(&Channel::closeInternal, - bind(&ChannelMap::value_type::second, _1))); - channels.clear(); + getVersion(), code, msg, classId, methodId))); + closeChannels(); connector->close(); } } +bool Connection::markClosed() +{ + Mutex::ScopedLock locker(shutdownLock); + if (isOpen) { + isOpen = false; + return true; + } else { + return false; + } +} + +void Connection::closeChannels() +{ + using boost::bind; + for_each(channels.begin(), channels.end(), + bind(&Channel::closeInternal, + bind(&ChannelMap::value_type::second, _1))); + channels.clear(); +} + void Connection::openChannel(Channel& channel) { ChannelId id = ++channelIdCounter; assert (channels.find(id) == channels.end()); |