diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-11-10 22:36:26 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-11-10 22:36:26 (GMT) |
commit | 6a20be61e229255f93d55f13be3346525698237a (patch) | |
tree | c7ed9949826b554297100267c560b2435c043955 | |
parent | d6322619cdfd34e62126cd9b8a09d95316fff6ae (diff) | |
download | swift-contrib-6a20be61e229255f93d55f13be3346525698237a.zip swift-contrib-6a20be61e229255f93d55f13be3346525698237a.tar.bz2 |
Close connection properly on disconnect and session end.
-rw-r--r-- | Swiften/Client/Client.cpp | 7 | ||||
-rw-r--r-- | Swiften/Client/Client.h | 2 |
2 files changed, 8 insertions, 1 deletions
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_; |