summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client')
-rw-r--r--Swiften/Client/Client.cpp17
-rw-r--r--Swiften/Client/Client.h2
2 files changed, 15 insertions, 4 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp
index 63a93a3..763c83e 100644
--- a/Swiften/Client/Client.cpp
+++ b/Swiften/Client/Client.cpp
@@ -45,15 +45,23 @@ void Client::connect() {
}
void Client::connect(const String& host) {
- assert(!connector_);
+ assert(!connector_); // Crash on reconnect is here.
connector_ = Connector::create(host, &resolver_, connectionFactory_, timerFactory_);
- connector_->onConnectFinished.connect(boost::bind(&Client::handleConnectorFinished, this, _1));
+ connector_->onConnectFinished.connect(boost::bind(&Client::handleConnectorFinished, this, _1, connector_));
connector_->setTimeoutMilliseconds(60*1000);
connector_->start();
}
-void Client::handleConnectorFinished(boost::shared_ptr<Connection> connection) {
+void Client::handleConnectorFinished(boost::shared_ptr<Connection> connection, Connector::ref connector) {
+ bool currentConnection = connector_ && (connector.get() == connector_.get());
// TODO: Add domain name resolver error
+ if (!currentConnection) {
+ /* disconnect() was called, this connection should be thrown away*/
+ if (connection) {
+ connection->disconnect();
+ }
+ return;
+ }
connector_.reset();
if (!connection) {
onError(ClientError::ConnectionError);
@@ -81,6 +89,9 @@ void Client::handleConnectorFinished(boost::shared_ptr<Connection> connection) {
}
void Client::disconnect() {
+ if (connector_) {
+ connector_.reset();
+ }
if (session_) {
session_->finish();
}
diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h
index 92e89f1..e0714bb 100644
--- a/Swiften/Client/Client.h
+++ b/Swiften/Client/Client.h
@@ -55,7 +55,7 @@ namespace Swift {
boost::signal<void (const String&)> onDataWritten;
private:
- void handleConnectorFinished(boost::shared_ptr<Connection>);
+ void handleConnectorFinished(boost::shared_ptr<Connection>, Connector::ref);
void send(boost::shared_ptr<Stanza>);
virtual String getNewIQID();
void handleElement(boost::shared_ptr<Element>);