summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-05-27 13:24:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-05-27 17:34:56 (GMT)
commit109e50103d757d880e7ce390482951111dad1e22 (patch)
treecbb9cdb9f63eda164727a24653c8ef8bdf283a46 /Swiften/Client
parent0bdb45be4aa66dcc478d5f061096b1adbaa3ab2c (diff)
downloadswift-contrib-109e50103d757d880e7ce390482951111dad1e22.zip
swift-contrib-109e50103d757d880e7ce390482951111dad1e22.tar.bz2
Cleaning up code paths for rapid disconnect/reconnect.
This includes a fix in OpensSSLContext that stops assert failures when more data is received on a connection after a write has failed. It's worth investigating why this happens, stopping it doing so, and re-instate the assert. Resolves: #402
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>);