summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-10-10 07:37:12 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-10-10 07:46:36 (GMT)
commit150542a5c60fe49f4e164ffdaa51236795426214 (patch)
tree238eda2d89e8347e32d2eabc224633c518fe5083 /Swiften/Client/CoreClient.cpp
parentf9187481a14493a729987ebbcfd10839b2439b96 (diff)
downloadswift-150542a5c60fe49f4e164ffdaa51236795426214.zip
swift-150542a5c60fe49f4e164ffdaa51236795426214.tar.bz2
Force disconnect signals when calling connect() shortly after disconnect().
Diffstat (limited to 'Swiften/Client/CoreClient.cpp')
-rw-r--r--Swiften/Client/CoreClient.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index dbc6de2..22e3612 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -41,9 +41,7 @@ CoreClient::CoreClient(const JID& jid, const SafeByteArray& password, NetworkFac
}
CoreClient::~CoreClient() {
- if ((session_ && !session_->isFinished()) || connection_) {
- std::cerr << "Warning: Client not disconnected properly" << std::endl;
- }
+ forceReset();
delete tlsFactories;
delete iqRouter_;
@@ -61,10 +59,11 @@ void CoreClient::connect(const ClientOptions& o) {
}
void CoreClient::connect(const std::string& host) {
+ forceReset();
+
SWIFT_LOG(debug) << "Connecting to host " << host << std::endl;
disconnectRequested_ = false;
assert(!connector_);
-
assert(proxyConnectionFactories.empty());
PlatformProxyProvider proxyProvider;
if(proxyProvider.getSOCKS5Proxy().isValid()) {
@@ -83,13 +82,7 @@ void CoreClient::connect(const std::string& host) {
}
void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connection) {
- connector_->onConnectFinished.disconnect(boost::bind(&CoreClient::handleConnectorFinished, this, _1));
- connector_.reset();
- foreach(ConnectionFactory* f, proxyConnectionFactories) {
- delete f;
- }
- proxyConnectionFactories.clear();
-
+ resetConnector();
if (!connection) {
if (options.forgetPassword) {
purgePassword();
@@ -151,15 +144,7 @@ void CoreClient::handleSessionFinished(boost::shared_ptr<Error> error) {
if (options.forgetPassword) {
purgePassword();
}
- session_->onFinished.disconnect(boost::bind(&CoreClient::handleSessionFinished, this, _1));
- session_->onNeedCredentials.disconnect(boost::bind(&CoreClient::handleNeedCredentials, this));
-
- sessionStream_->onDataRead.disconnect(boost::bind(&CoreClient::handleDataRead, this, _1));
- sessionStream_->onDataWritten.disconnect(boost::bind(&CoreClient::handleDataWritten, this, _1));
- sessionStream_.reset();
-
- connection_->disconnect();
- connection_.reset();
+ resetSession();
boost::optional<ClientError> actualError;
if (error) {
@@ -341,4 +326,36 @@ void CoreClient::purgePassword() {
safeClear(password_);
}
+void CoreClient::resetConnector() {
+ connector_->onConnectFinished.disconnect(boost::bind(&CoreClient::handleConnectorFinished, this, _1));
+ connector_.reset();
+ foreach(ConnectionFactory* f, proxyConnectionFactories) {
+ delete f;
+ }
+ proxyConnectionFactories.clear();
+}
+
+void CoreClient::resetSession() {
+ session_->onFinished.disconnect(boost::bind(&CoreClient::handleSessionFinished, this, _1));
+ session_->onNeedCredentials.disconnect(boost::bind(&CoreClient::handleNeedCredentials, this));
+
+ sessionStream_->onDataRead.disconnect(boost::bind(&CoreClient::handleDataRead, this, _1));
+ sessionStream_->onDataWritten.disconnect(boost::bind(&CoreClient::handleDataWritten, this, _1));
+ sessionStream_.reset();
+
+ connection_->disconnect();
+ connection_.reset();
+}
+
+void CoreClient::forceReset() {
+ if (connector_) {
+ std::cerr << "Warning: Client not disconnected properly: Connector still active" << std::endl;
+ resetConnector();
+ }
+ if (sessionStream_ || connection_) {
+ std::cerr << "Warning: Client not disconnected properly: Session still active" << std::endl;
+ resetSession();
+ }
+}
+
}