You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2007/04/16 13:32:48 UTC
svn commit: r529209 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/client:
ClientConnection.cpp Connection.h Connector.cpp Connector.h
Author: gsim
Date: Mon Apr 16 04:32:43 2007
New Revision: 529209
URL: http://svn.apache.org/viewvc?view=rev&rev=529209
Log:
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
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h
incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp?view=diff&rev=529209&r1=529208&r2=529209
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ClientConnection.cpp Mon Apr 16 04:32:43 2007
@@ -75,28 +75,47 @@
}
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) {
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h?view=diff&rev=529209&r1=529208&r2=529209
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connection.h Mon Apr 16 04:32:43 2007
@@ -26,6 +26,7 @@
#include "qpid/QpidError.h"
#include "ClientChannel.h"
#include "Connector.h"
+#include "qpid/sys/Mutex.h"
#include "qpid/sys/ShutdownHandler.h"
#include "qpid/sys/TimeoutHandler.h"
@@ -81,13 +82,16 @@
Connector defaultConnector;
Connector* connector;
framing::OutputHandler* out;
- volatile bool isOpen;
+ bool isOpen;
+ sys::Mutex shutdownLock;
Channel channel0;
bool debug;
void erase(framing::ChannelId);
void channelException(
Channel&, framing::AMQMethodBody*, const QpidError&);
+ void closeChannels();
+ bool markClosed();
// TODO aconway 2007-01-26: too many friendships, untagle these classes.
friend class Channel;
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?view=diff&rev=529209&r1=529208&r2=529209
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Mon Apr 16 04:32:43 2007
@@ -61,9 +61,10 @@
}
void Connector::close(){
- closed = true;
- socket.close();
- receiver.join();
+ if (markClosed()) {
+ socket.close();
+ receiver.join();
+ }
}
void Connector::setInputHandler(InputHandler* handler){
@@ -106,9 +107,19 @@
}
void Connector::handleClosed(){
- closed = true;
- socket.close();
- if(shutdownHandler) shutdownHandler->shutdown();
+ if (markClosed()) {
+ socket.close();
+ if(shutdownHandler) shutdownHandler->shutdown();
+ }
+}
+
+bool Connector::markClosed(){
+ if (closed) {
+ return false;
+ } else {
+ closed = true;
+ return true;
+ }
}
void Connector::checkIdle(ssize_t status){
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h?view=diff&rev=529209&r1=529208&r2=529209
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/Connector.h Mon Apr 16 04:32:43 2007
@@ -46,6 +46,7 @@
framing::ProtocolVersion version;
bool closed;
+ sys::Mutex closedLock;
int64_t lastIn;
int64_t lastOut;
@@ -74,6 +75,7 @@
void run();
void handleClosed();
+ bool markClosed();
friend class Channel;
public: