summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/ChainedConnector.cpp')
-rw-r--r--Swiften/Network/ChainedConnector.cpp106
1 files changed, 53 insertions, 53 deletions
diff --git a/Swiften/Network/ChainedConnector.cpp b/Swiften/Network/ChainedConnector.cpp
index 3cc4057..08c4aac 100644
--- a/Swiften/Network/ChainedConnector.cpp
+++ b/Swiften/Network/ChainedConnector.cpp
@@ -18,79 +18,79 @@
using namespace Swift;
ChainedConnector::ChainedConnector(
- const std::string& hostname,
- int port,
- const boost::optional<std::string>& serviceLookupPrefix,
- DomainNameResolver* resolver,
- const std::vector<ConnectionFactory*>& connectionFactories,
- TimerFactory* timerFactory) :
- hostname(hostname),
- port(port),
- serviceLookupPrefix(serviceLookupPrefix),
- resolver(resolver),
- connectionFactories(connectionFactories),
- timerFactory(timerFactory),
- timeoutMilliseconds(0) {
+ const std::string& hostname,
+ int port,
+ const boost::optional<std::string>& serviceLookupPrefix,
+ DomainNameResolver* resolver,
+ const std::vector<ConnectionFactory*>& connectionFactories,
+ TimerFactory* timerFactory) :
+ hostname(hostname),
+ port(port),
+ serviceLookupPrefix(serviceLookupPrefix),
+ resolver(resolver),
+ connectionFactories(connectionFactories),
+ timerFactory(timerFactory),
+ timeoutMilliseconds(0) {
}
ChainedConnector::~ChainedConnector() {
- if (currentConnector) {
- currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
- currentConnector->stop();
- currentConnector.reset();
- }
+ if (currentConnector) {
+ currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
+ currentConnector->stop();
+ currentConnector.reset();
+ }
}
void ChainedConnector::setTimeoutMilliseconds(int milliseconds) {
- timeoutMilliseconds = milliseconds;
+ timeoutMilliseconds = milliseconds;
}
void ChainedConnector::start() {
- SWIFT_LOG(debug) << "Starting queued connector for " << hostname << std::endl;
+ SWIFT_LOG(debug) << "Starting queued connector for " << hostname << std::endl;
- connectionFactoryQueue = std::deque<ConnectionFactory*>(connectionFactories.begin(), connectionFactories.end());
- tryNextConnectionFactory();
+ connectionFactoryQueue = std::deque<ConnectionFactory*>(connectionFactories.begin(), connectionFactories.end());
+ tryNextConnectionFactory();
}
void ChainedConnector::stop() {
- if (currentConnector) {
- currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
- currentConnector->stop();
- currentConnector.reset();
- }
- finish(boost::shared_ptr<Connection>(), boost::shared_ptr<Error>());
+ if (currentConnector) {
+ currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
+ currentConnector->stop();
+ currentConnector.reset();
+ }
+ finish(boost::shared_ptr<Connection>(), boost::shared_ptr<Error>());
}
void ChainedConnector::tryNextConnectionFactory() {
- assert(!currentConnector);
- if (connectionFactoryQueue.empty()) {
- SWIFT_LOG(debug) << "No more connection factories" << std::endl;
- finish(boost::shared_ptr<Connection>(), lastError);
- }
- else {
- ConnectionFactory* connectionFactory = connectionFactoryQueue.front();
- SWIFT_LOG(debug) << "Trying next connection factory: " << typeid(*connectionFactory).name() << std::endl;
- connectionFactoryQueue.pop_front();
- currentConnector = Connector::create(hostname, port, serviceLookupPrefix, resolver, connectionFactory, timerFactory);
- currentConnector->setTimeoutMilliseconds(timeoutMilliseconds);
- currentConnector->onConnectFinished.connect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
- currentConnector->start();
- }
+ assert(!currentConnector);
+ if (connectionFactoryQueue.empty()) {
+ SWIFT_LOG(debug) << "No more connection factories" << std::endl;
+ finish(boost::shared_ptr<Connection>(), lastError);
+ }
+ else {
+ ConnectionFactory* connectionFactory = connectionFactoryQueue.front();
+ SWIFT_LOG(debug) << "Trying next connection factory: " << typeid(*connectionFactory).name() << std::endl;
+ connectionFactoryQueue.pop_front();
+ currentConnector = Connector::create(hostname, port, serviceLookupPrefix, resolver, connectionFactory, timerFactory);
+ currentConnector->setTimeoutMilliseconds(timeoutMilliseconds);
+ currentConnector->onConnectFinished.connect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
+ currentConnector->start();
+ }
}
void ChainedConnector::handleConnectorFinished(boost::shared_ptr<Connection> connection, boost::shared_ptr<Error> error) {
- SWIFT_LOG(debug) << "Connector finished" << std::endl;
- currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
- lastError = error;
- currentConnector.reset();
- if (connection) {
- finish(connection, error);
- }
- else {
- tryNextConnectionFactory();
- }
+ SWIFT_LOG(debug) << "Connector finished" << std::endl;
+ currentConnector->onConnectFinished.disconnect(boost::bind(&ChainedConnector::handleConnectorFinished, this, _1, _2));
+ lastError = error;
+ currentConnector.reset();
+ if (connection) {
+ finish(connection, error);
+ }
+ else {
+ tryNextConnectionFactory();
+ }
}
void ChainedConnector::finish(boost::shared_ptr<Connection> connection, boost::shared_ptr<Error> error) {
- onConnectFinished(connection, error);
+ onConnectFinished(connection, error);
}