summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-12-04 15:56:42 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-12-04 17:33:59 (GMT)
commitd96f856fea35e8a8f6e426318a87f044223de8d8 (patch)
tree7050a69456b523c1810e95964784fed760deecaf
parenta6f8c4e4579b93b3e004229dcdeb098bd5b356a4 (diff)
downloadswift-contrib-d96f856fea35e8a8f6e426318a87f044223de8d8.zip
swift-contrib-d96f856fea35e8a8f6e426318a87f044223de8d8.tar.bz2
Make sure we say the session's ended after calling close() with BOSH.
Change-Id: I35b290cb75657e2d9778cc81d83c8a52693f1103 Resolves: #1184
-rw-r--r--Swiften/Network/BOSHConnection.cpp7
-rw-r--r--Swiften/Network/BOSHConnectionPool.cpp33
2 files changed, 29 insertions, 11 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index 539109a..377373d 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -60,11 +60,14 @@ void BOSHConnection::cancelConnector() {
}
void BOSHConnection::disconnect() {
- cancelConnector();
- if(connection_) {
+ if (connection_) {
connection_->disconnect();
sid_ = "";
}
+ else {
+ /* handleDisconnected takes care of the connector_ as well */
+ handleDisconnected(boost::optional<Connection::Error>());
+ }
}
void BOSHConnection::restartStream() {
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
@@ -45,7 +45,14 @@ 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;
}
@@ -82,12 +89,16 @@ void BOSHConnectionPool::writeFooter() {
}
void BOSHConnectionPool::close() {
- /* TODO: Send a terminate here. */
- std::vector<BOSHConnection::ref> connectionCopies = connections;
- foreach (BOSHConnection::ref connection, connectionCopies) {
- if (connection) {
- connection->disconnect();
- destroyConnection(connection);
+ if (!sid.empty()) {
+ writeFooter();
+ }
+ else {
+ pendingTerminate = true;
+ std::vector<BOSHConnection::ref> connectionCopies = connections;
+ foreach (BOSHConnection::ref connection, connectionCopies) {
+ if (connection) {
+ connection->disconnect();
+ }
}
}
}
@@ -158,7 +169,8 @@ void BOSHConnectionPool::tryToSendQueuedData() {
rid++;
suitableConnection->setRID(rid);
suitableConnection->terminateStream();
- onSessionTerminated(boost::shared_ptr<BOSHError>());
+ sid = "";
+ close();
}
}
if (!pendingTerminate) {
@@ -200,7 +212,10 @@ 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));
}
else {