summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-10 22:36:26 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-10 22:36:26 (GMT)
commit6a20be61e229255f93d55f13be3346525698237a (patch)
treec7ed9949826b554297100267c560b2435c043955 /Swiften/Client
parentd6322619cdfd34e62126cd9b8a09d95316fff6ae (diff)
downloadswift-6a20be61e229255f93d55f13be3346525698237a.zip
swift-6a20be61e229255f93d55f13be3346525698237a.tar.bz2
Close connection properly on disconnect and session end.
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/Client.cpp7
-rw-r--r--Swiften/Client/Client.h2
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
@@ -30,12 +30,13 @@ Client::~Client() {
bool Client::isAvailable() {
return session_;
}
void Client::connect() {
+ assert(!connection_);
DomainNameResolver resolver;
try {
HostAddressPort remote = resolver.resolve(jid_.getDomain().getUTF8String());
connection_ = connectionFactory_->createConnection();
connection_->onConnectFinished.connect(boost::bind(&Client::handleConnectionConnectFinished, this, _1));
connection_->connect(remote);
@@ -70,12 +71,16 @@ void Client::handleConnectionConnectFinished(bool error) {
void Client::disconnect() {
if (session_) {
session_->finish();
session_.reset();
}
+ closeConnection();
+}
+
+void Client::closeConnection() {
if (connection_) {
connection_->disconnect();
connection_.reset();
}
}
@@ -121,12 +126,13 @@ void Client::handleElement(boost::shared_ptr<Element> element) {
void Client::setCertificate(const String& certificate) {
certificate_ = 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)) {
switch(actualError->type) {
case ClientSession::Error::AuthenticationFailedError:
clientError = ClientError(ClientError::AuthenticationFailedError);
@@ -169,12 +175,13 @@ void Client::handleSessionFinished(boost::shared_ptr<Error> error) {
clientError = ClientError(ClientError::ConnectionWriteError);
break;
}
}
onError(clientError);
}
+ session_.reset();
}
void Client::handleNeedCredentials() {
session_->sendCredentials(password_);
}
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
@@ -52,13 +52,13 @@ namespace Swift {
void handleElement(boost::shared_ptr<Element>);
void handleSessionFinished(boost::shared_ptr<Error>);
void handleNeedCredentials();
void handleDataRead(const String&);
void handleDataWritten(const String&);
- void reset();
+ void closeConnection();
private:
JID jid_;
String password_;
IDGenerator idGenerator_;
ConnectionFactory* connectionFactory_;