summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-12-31 13:27:52 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-12-31 13:27:52 (GMT)
commit152c455e18aae9b613f17bca8bba4a2beafe0228 (patch)
treecde533a0bf5dbe014acba3eb2645761ade53dd20 /Swiften/Network/Connector.cpp
parent3625bf9f94aad738b6d44da4b8f70c60cd167647 (diff)
downloadswift-152c455e18aae9b613f17bca8bba4a2beafe0228.zip
swift-152c455e18aae9b613f17bca8bba4a2beafe0228.tar.bz2
Added tests for timing out initial connect.
Diffstat (limited to 'Swiften/Network/Connector.cpp')
-rw-r--r--Swiften/Network/Connector.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp
index e424f64..9ea5a7f 100644
--- a/Swiften/Network/Connector.cpp
+++ b/Swiften/Network/Connector.cpp
@@ -1,62 +1,66 @@
#include "Swiften/Network/Connector.h"
#include <boost/bind.hpp>
#include <iostream>
#include "Swiften/Network/ConnectionFactory.h"
#include "Swiften/Network/DomainNameResolver.h"
#include "Swiften/Network/DomainNameAddressQuery.h"
namespace Swift {
Connector::Connector(const String& hostname, DomainNameResolver* resolver, ConnectionFactory* connectionFactory) : hostname(hostname), resolver(resolver), connectionFactory(connectionFactory), queriedAllHosts(true) {
}
+void Connector::setTimeoutMilliseconds(int milliseconds) {
+ timeoutMilliseconds = milliseconds;
+}
+
void Connector::start() {
//std::cout << "Connector::start()" << std::endl;
assert(!currentConnection);
assert(!serviceQuery);
queriedAllHosts = false;
serviceQuery = resolver->createServiceQuery("_xmpp-client._tcp." + hostname);
serviceQuery->onResult.connect(boost::bind(&Connector::handleServiceQueryResult, this, _1));
serviceQuery->run();
}
void Connector::queryAddress(const String& hostname) {
assert(!addressQuery);
addressQuery = resolver->createAddressQuery(hostname);
addressQuery->onResult.connect(boost::bind(&Connector::handleAddressQueryResult, this, _1, _2));
addressQuery->run();
}
void Connector::handleServiceQueryResult(const std::vector<DomainNameServiceQuery::Result>& result) {
//std::cout << "Received SRV results" << std::endl;
serviceQueryResults = std::deque<DomainNameServiceQuery::Result>(result.begin(), result.end());
serviceQuery.reset();
tryNextHostname();
}
void Connector::tryNextHostname() {
if (queriedAllHosts) {
//std::cout << "Connector::tryNextHostName(): Queried all hosts. Error." << std::endl;
onConnectFinished(boost::shared_ptr<Connection>());
}
else if (serviceQueryResults.empty()) {
//std::cout << "Connector::tryNextHostName(): Falling back on A resolution" << std::endl;
// Fall back on simple address resolving
queriedAllHosts = true;
queryAddress(hostname);
}
else {
//std::cout << "Connector::tryNextHostName(): Querying next address" << std::endl;
queryAddress(serviceQueryResults.front().hostname);
}
}
void Connector::handleAddressQueryResult(const HostAddress& address, boost::optional<DomainNameResolveError> error) {
//std::cout << "Connector::handleAddressQueryResult(): Start" << std::endl;
addressQuery.reset();
if (!serviceQueryResults.empty()) {
DomainNameServiceQuery::Result serviceQueryResult = serviceQueryResults.front();
serviceQueryResults.pop_front();
if (error) {