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/09/26 12:51:13 UTC

svn commit: r579582 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/client: ConnectionHandler.cpp ConnectionImpl.cpp ConnectionImpl.h

Author: gsim
Date: Wed Sep 26 03:51:12 2007
New Revision: 579582

URL: http://svn.apache.org/viewvc?rev=579582&view=rev
Log:
Detect that connection is already closed on attempt to close()


Modified:
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp?rev=579582&r1=579581&r2=579582&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionHandler.cpp Wed Sep 26 03:51:12 2007
@@ -102,6 +102,9 @@
 
 void ConnectionHandler::close()
 {
+    if (getState() != OPEN) {
+        throw Exception("Connection not open");
+    }
     setState(CLOSING);
     send(ConnectionCloseBody(version, 200, OK, 0, 0));
     waitFor(CLOSED);

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp?rev=579582&r1=579581&r2=579582&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.cpp Wed Sep 26 03:51:12 2007
@@ -26,7 +26,7 @@
 using namespace qpid::framing;
 using namespace qpid::sys;
 
-ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) : connector(c)
+ConnectionImpl::ConnectionImpl(boost::shared_ptr<Connector> c) : connector(c), isClosed(false)
 {
     handler.in = boost::bind(&ConnectionImpl::incoming, this, _1);
     handler.out = boost::bind(&Connector::send, connector, _1);
@@ -81,6 +81,7 @@
 
 void ConnectionImpl::close()
 {
+    assertNotClosed();
     handler.close();
 }
 
@@ -120,6 +121,7 @@
         i->second->closed(code, text);
     }
     sessions.clear();
+    isClosed = true;
 }
 
 SessionCore::shared_ptr ConnectionImpl::find(uint16_t id)
@@ -130,4 +132,10 @@
         throw ConnectionException(504, (boost::format("Invalid channel number %g") % id).str());
     }
     return i->second;
+}
+
+void ConnectionImpl::assertNotClosed()
+{
+    Mutex::ScopedLock l(lock);
+    if (isClosed) throw Exception("Connection has been closed");
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h?rev=579582&r1=579581&r2=579582&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionImpl.h Wed Sep 26 03:51:12 2007
@@ -46,6 +46,7 @@
     boost::shared_ptr<Connector> connector;
     framing::ProtocolVersion version;
     sys::Mutex lock;
+    bool isClosed;
 
     void incoming(framing::AMQFrame& frame);    
     void closed();
@@ -54,6 +55,7 @@
     void idleIn();
     void shutdown();
     void signalClose(uint16_t, const std::string&);
+    void assertNotClosed();
     SessionCore::shared_ptr find(uint16_t);
 
 public: