summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-08-13 18:30:58 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-08-13 18:30:58 (GMT)
commit0670ded9cfa064f3558435cecb0e7866833d62dd (patch)
tree2c706dce997acd960123ac75a72ae6a600b156e6 /Swiften/Network/Connector.cpp
parentf799cce739f89225258dfbd2e0099e8a71d99af4 (diff)
downloadswift-contrib-0670ded9cfa064f3558435cecb0e7866833d62dd.zip
swift-contrib-0670ded9cfa064f3558435cecb0e7866833d62dd.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.cpp10
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);
}
};