summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/BOSHConnectionPool.cpp')
-rw-r--r--Swiften/Network/BOSHConnectionPool.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/Swiften/Network/BOSHConnectionPool.cpp b/Swiften/Network/BOSHConnectionPool.cpp
index bb24aa5..fdfe420 100644
--- a/Swiften/Network/BOSHConnectionPool.cpp
+++ b/Swiften/Network/BOSHConnectionPool.cpp
@@ -15,5 +15,5 @@
#include <Swiften/Network/TLSConnectionFactory.h>
#include <Swiften/Network/HTTPConnectProxiedConnectionFactory.h>
-#include <Swiften/Network/CachingNameOnlyDomainNameResolver.h>
+#include <Swiften/Network/CachingDomainNameResolver.h>
namespace Swift {
@@ -22,5 +22,4 @@ BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, DomainNameResolver* r
connectionFactory(connectionFactoryParameter),
xmlParserFactory(parserFactory),
- tlsFactory(tlsFactory),
timerFactory(timerFactory),
rid(initialRID),
@@ -31,10 +30,10 @@ BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, DomainNameResolver* r
pendingRestart(false) {
- if (!boshHTTPConnectProxyURL.empty()) {
+ if (!boshHTTPConnectProxyURL.isEmpty()) {
if (boshHTTPConnectProxyURL.getScheme() == "https") {
connectionFactory = new TLSConnectionFactory(tlsFactory, connectionFactory);
myConnectionFactories.push_back(connectionFactory);
}
- connectionFactory = new HTTPConnectProxiedConnectionFactory(realResolver, connectionFactory, timerFactory, eventLoop, boshHTTPConnectProxyURL.getHost(), boshHTTPConnectProxyURL.getPort(), boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword);
+ connectionFactory = new HTTPConnectProxiedConnectionFactory(realResolver, connectionFactory, timerFactory, boshHTTPConnectProxyURL.getHost(), URL::getPortOrDefaultPort(boshHTTPConnectProxyURL), boshHTTPConnectProxyAuthID, boshHTTPConnectProxyAuthPassword);
}
if (boshURL.getScheme() == "https") {
@@ -42,10 +41,17 @@ BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, DomainNameResolver* r
myConnectionFactories.push_back(connectionFactory);
}
- resolver = new CachingNameOnlyDomainNameResolver(realResolver, eventLoop);
+ resolver = new CachingDomainNameResolver(realResolver, eventLoop);
createConnection();
}
BOSHConnectionPool::~BOSHConnectionPool() {
- close();
+ /* Don't do a normal close here. Instead kill things forcibly, as close() or writeFooter() will already have been called */
+ std::vector<BOSHConnection::ref> connectionCopies = connections;
+ foreach (BOSHConnection::ref connection, connectionCopies) {
+ if (connection) {
+ destroyConnection(connection);
+ connection->disconnect();
+ }
+ }
foreach (ConnectionFactory* factory, myConnectionFactories) {
delete factory;
@@ -84,10 +90,14 @@ void BOSHConnectionPool::writeFooter() {
void BOSHConnectionPool::close() {
- /* TODO: Send a terminate here. */
+ if (!sid.empty()) {
+ writeFooter();
+ }
+ else {
+ pendingTerminate = true;
std::vector<BOSHConnection::ref> connectionCopies = connections;
foreach (BOSHConnection::ref connection, connectionCopies) {
if (connection) {
connection->disconnect();
- destroyConnection(connection);
+ }
}
}
@@ -160,5 +170,6 @@ void BOSHConnectionPool::tryToSendQueuedData() {
suitableConnection->setRID(rid);
suitableConnection->terminateStream();
- onSessionTerminated(boost::shared_ptr<BOSHError>());
+ sid = "";
+ close();
}
}
@@ -200,9 +211,12 @@ void BOSHConnectionPool::handleHTTPError(const std::string& /*errorCode*/) {
}
-void BOSHConnectionPool::handleConnectionDisconnected(bool error, BOSHConnection::ref connection) {
+void BOSHConnectionPool::handleConnectionDisconnected(bool/* error*/, BOSHConnection::ref connection) {
destroyConnection(connection);
- if (false && error) {
- handleSessionTerminated(boost::make_shared<BOSHError>(BOSHError::UndefinedCondition));
+ if (pendingTerminate && sid.empty() && connections.empty()) {
+ handleSessionTerminated(BOSHError::ref());
}
+ //else if (error) {
+ // handleSessionTerminated(boost::make_shared<BOSHError>(BOSHError::UndefinedCondition));
+ //}
else {
/* We might have just freed up a connection slot to send with */
@@ -212,5 +226,5 @@ void BOSHConnectionPool::handleConnectionDisconnected(bool error, BOSHConnection
boost::shared_ptr<BOSHConnection> BOSHConnectionPool::createConnection() {
- Connector::ref connector = Connector::create(boshURL.getHost(), resolver, connectionFactory, timerFactory, boshURL.getPort());
+ Connector::ref connector = Connector::create(boshURL.getHost(), URL::getPortOrDefaultPort(boshURL), boost::optional<std::string>(), resolver, connectionFactory, timerFactory);
BOSHConnection::ref connection = BOSHConnection::create(boshURL, connector, xmlParserFactory);
connection->onXMPPDataRead.connect(boost::bind(&BOSHConnectionPool::handleDataRead, this, _1));