From 6a20be61e229255f93d55f13be3346525698237a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Tue, 10 Nov 2009 23:36:26 +0100
Subject: Close connection properly on disconnect and session end.


diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 1b662f5..85db4ac 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -33,6 +33,7 @@ bool Client::isAvailable() {
 }
 
 void Client::connect() {
+	assert(!connection_);
 	DomainNameResolver resolver;
 	try {
 		HostAddressPort remote = resolver.resolve(jid_.getDomain().getUTF8String());
@@ -73,6 +74,10 @@ void Client::disconnect() {
 		session_->finish();
 		session_.reset();
 	}
+	closeConnection();
+}
+
+void Client::closeConnection() {
 	if (connection_) {
 		connection_->disconnect();
 		connection_.reset();
@@ -124,6 +129,7 @@ void Client::setCertificate(const String& certificate) {
 }
 
 void Client::handleSessionFinished(boost::shared_ptr<Error> error) {
+	closeConnection();
 	if (error) {
 		ClientError clientError;
 		if (boost::shared_ptr<ClientSession::Error> actualError = boost::dynamic_pointer_cast<ClientSession::Error>(error)) {
@@ -172,6 +178,7 @@ void Client::handleSessionFinished(boost::shared_ptr<Error> error) {
 		}
 		onError(clientError);
 	}
+	session_.reset();
 }
 
 void Client::handleNeedCredentials() {
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 5188789..3f7d350 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -55,7 +55,7 @@ namespace Swift {
 			void handleDataRead(const String&);
 			void handleDataWritten(const String&);
 
-			void reset();
+			void closeConnection();
 
 		private:
 			JID jid_;
-- 
cgit v0.10.2-6-g49f6