summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-03-05 15:26:30 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-05 15:26:30 (GMT)
commite1602cbe8c5fb1525bc66ecf5d7a939816f259c5 (patch)
tree342b54f4037063a51a0ff933dc3d52afec23bb2e /Swiften/Network/BOSHConnectionPool.cpp
parentfe24fd560ec2302306857a52a07155c93f5dde69 (diff)
downloadswift-contrib-e1602cbe8c5fb1525bc66ecf5d7a939816f259c5.zip
swift-contrib-e1602cbe8c5fb1525bc66ecf5d7a939816f259c5.tar.bz2
Fix segfaults and deadcode
Diffstat (limited to 'Swiften/Network/BOSHConnectionPool.cpp')
-rw-r--r--Swiften/Network/BOSHConnectionPool.cpp3
1 files changed, 0 insertions, 3 deletions
diff --git a/Swiften/Network/BOSHConnectionPool.cpp b/Swiften/Network/BOSHConnectionPool.cpp
index 7d43f42..bb24aa5 100644
--- a/Swiften/Network/BOSHConnectionPool.cpp
+++ b/Swiften/Network/BOSHConnectionPool.cpp
@@ -111,89 +111,86 @@ void BOSHConnectionPool::handleConnectFinished(bool error, BOSHConnection::ref c
connection->startStream(to, rid);
}
if (pendingRestart) {
restartStream();
}
tryToSendQueuedData();
}
}
BOSHConnection::ref BOSHConnectionPool::getSuitableConnection() {
BOSHConnection::ref suitableConnection;
foreach (BOSHConnection::ref connection, connections) {
if (connection->isReadyToSend()) {
suitableConnection = connection;
break;
}
}
if (!suitableConnection && connections.size() < requestLimit) {
/* This is not a suitable connection because it won't have yet connected and added TLS if needed. */
BOSHConnection::ref newConnection = createConnection();
newConnection->setSID(sid);
}
assert(connections.size() <= requestLimit);
assert((!suitableConnection) || suitableConnection->isReadyToSend());
return suitableConnection;
}
void BOSHConnectionPool::tryToSendQueuedData() {
if (sid.empty()) {
/* If we've not got as far as stream start yet, pend */
return;
}
BOSHConnection::ref suitableConnection = getSuitableConnection();
- bool sent = false;
bool toSend = !dataQueue.empty();
if (suitableConnection) {
if (toSend) {
rid++;
suitableConnection->setRID(rid);
SafeByteArray data;
foreach (const SafeByteArray& datum, dataQueue) {
data.insert(data.end(), datum.begin(), datum.end());
}
suitableConnection->write(data);
- sent = true;
dataQueue.clear();
}
else if (pendingTerminate) {
rid++;
suitableConnection->setRID(rid);
suitableConnection->terminateStream();
- sent = true;
onSessionTerminated(boost::shared_ptr<BOSHError>());
}
}
if (!pendingTerminate) {
/* Ensure there's always a session waiting to read data for us */
bool pending = false;
foreach (BOSHConnection::ref connection, connections) {
if (connection && !connection->isReadyToSend()) {
pending = true;
}
}
if (!pending) {
if (restartCount >= 1) {
/* Don't open a second connection until we've restarted the stream twice - i.e. we've authed and resource bound.*/
if (suitableConnection) {
rid++;
suitableConnection->setRID(rid);
suitableConnection->write(createSafeByteArray(""));
}
else {
/* My thought process I went through when writing this, to aid anyone else confused why this can happen...
*
* What to do here? I think this isn't possible.
If you didn't have two connections, suitable would have made one.
If you have two connections and neither is suitable, pending would be true.
If you have a non-pending connection, it's suitable.
If I decide to do something here, remove assert above.
Ah! Yes, because there's a period between creating the connection and it being connected. */
}
}
}
}
}