diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-08-13 18:30:58 (GMT) |
---|---|---|
committer | Cătălin Badea <catalin.badea392@gmail.com> | 2012-08-15 10:24:56 (GMT) |
commit | 7ef1133ee60eab2ae204e6898dc504ca58ba4496 (patch) | |
tree | af63f42de9d4bf070ef6878d2abe639281531c98 /Swiften/Network/Connector.cpp | |
parent | d9e90fa37405092bfde2fa8f1bb0ab6208f716d1 (diff) | |
download | swift-contrib-7ef1133ee60eab2ae204e6898dc504ca58ba4496.zip swift-contrib-7ef1133ee60eab2ae204e6898dc504ca58ba4496.tar.bz2 |
Set timeout on each connection attempt, instead of global connect timeout.
Resolves: #962
Diffstat (limited to 'Swiften/Network/Connector.cpp')
-rw-r--r-- | Swiften/Network/Connector.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp index 02ebb02..5ab3b92 100644 --- a/Swiften/Network/Connector.cpp +++ b/Swiften/Network/Connector.cpp @@ -37,7 +37,6 @@ void Connector::start() { if (timeoutMilliseconds > 0) { timer = timerFactory->createTimer(timeoutMilliseconds); timer->onTick.connect(boost::bind(&Connector::handleTimeout, shared_from_this())); - timer->start(); } serviceQuery->run(); } @@ -129,10 +128,17 @@ void Connector::tryConnect(const HostAddressPort& target) { currentConnection = connectionFactory->createConnection(); currentConnection->onConnectFinished.connect(boost::bind(&Connector::handleConnectionConnectFinished, shared_from_this(), _1)); currentConnection->connect(target); + if (timer) { + timer->start(); + } } void Connector::handleConnectionConnectFinished(bool error) { SWIFT_LOG(debug) << "ConnectFinished: " << (error ? "error" : "success") << std::endl; + if (timer) { + timer->stop(); + timer.reset(); + } currentConnection->onConnectFinished.disconnect(boost::bind(&Connector::handleConnectionConnectFinished, shared_from_this(), _1)); if (error) { currentConnection.reset(); @@ -174,7 +180,7 @@ void Connector::finish(boost::shared_ptr<Connection> connection) { void Connector::handleTimeout() { SWIFT_LOG(debug) << "Timeout" << std::endl; - finish(boost::shared_ptr<Connection>()); + handleConnectionConnectFinished(true); } }; |