diff options
Diffstat (limited to 'Swiften/Network/BOSHConnectionPool.cpp')
-rw-r--r-- | Swiften/Network/BOSHConnectionPool.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/Swiften/Network/BOSHConnectionPool.cpp b/Swiften/Network/BOSHConnectionPool.cpp index 83310fb..e535deb 100644 --- a/Swiften/Network/BOSHConnectionPool.cpp +++ b/Swiften/Network/BOSHConnectionPool.cpp @@ -46,5 +46,12 @@ BOSHConnectionPool::BOSHConnectionPool(const URL& boshURL, DomainNameResolver* r 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; @@ -83,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); + } } } @@ -159,5 +170,6 @@ void BOSHConnectionPool::tryToSendQueuedData() { suitableConnection->setRID(rid); suitableConnection->terminateStream(); - onSessionTerminated(boost::shared_ptr<BOSHError>()); + sid = ""; + close(); } } @@ -201,5 +213,8 @@ void BOSHConnectionPool::handleHTTPError(const std::string& /*errorCode*/) { void BOSHConnectionPool::handleConnectionDisconnected(bool error, BOSHConnection::ref connection) { destroyConnection(connection); - if (false && error) { + if (pendingTerminate && sid.empty() && connections.empty()) { + handleSessionTerminated(BOSHError::ref()); + } + else if (false && error) { handleSessionTerminated(boost::make_shared<BOSHError>(BOSHError::UndefinedCondition)); } |