wsd: do not enqueue messages on closed sessions
Also corrects the counting of number of active sessions when broadcasting messages. Change-Id: I5ab5995ed2cbc18b215542d0b2c9568957fd6a3a Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
a674a0d52e
commit
1c07d507ee
3 changed files with 21 additions and 7 deletions
|
@ -1923,6 +1923,12 @@ bool ClientSession::forwardToClient(const std::shared_ptr<Message>& payload)
|
|||
|
||||
void ClientSession::enqueueSendMessage(const std::shared_ptr<Message>& data)
|
||||
{
|
||||
if (isCloseFrame())
|
||||
{
|
||||
LOG_TRC(getName() << ": Connection closed, dropping message " << data->id());
|
||||
return;
|
||||
}
|
||||
|
||||
const std::shared_ptr<DocumentBroker> docBroker = _docBroker.lock();
|
||||
LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", );
|
||||
docBroker->assertCorrectThread();
|
||||
|
|
|
@ -82,11 +82,15 @@ public:
|
|||
|
||||
bool sendBinaryFrame(const char* buffer, int length) override
|
||||
{
|
||||
auto payload = std::make_shared<Message>(buffer, length, Message::Dir::Out);
|
||||
enqueueSendMessage(payload);
|
||||
if (!isCloseFrame())
|
||||
{
|
||||
enqueueSendMessage(std::make_shared<Message>(buffer, length, Message::Dir::Out));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sendTile(const std::string &header, const TileCache::Tile &tile)
|
||||
{
|
||||
// FIXME: performance - optimize away this copy ...
|
||||
|
@ -101,11 +105,15 @@ public:
|
|||
|
||||
bool sendTextFrame(const char* buffer, const int length) override
|
||||
{
|
||||
auto payload = std::make_shared<Message>(buffer, length, Message::Dir::Out);
|
||||
enqueueSendMessage(payload);
|
||||
if (!isCloseFrame())
|
||||
{
|
||||
enqueueSendMessage(std::make_shared<Message>(buffer, length, Message::Dir::Out));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void enqueueSendMessage(const std::shared_ptr<Message>& data);
|
||||
|
||||
|
|
|
@ -3263,7 +3263,7 @@ std::size_t DocumentBroker::broadcastMessage(const std::string& message) const
|
|||
std::size_t count = 0;
|
||||
for (const auto& sessionIt : _sessions)
|
||||
{
|
||||
count += sessionIt.second->sendTextFrame(message);
|
||||
count += (!sessionIt.second->isCloseFrame() && sessionIt.second->sendTextFrame(message));
|
||||
}
|
||||
|
||||
return count;
|
||||
|
|
Loading…
Reference in a new issue