[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Sep 21 05:14:22 UTC 2016
loolwsd/DocumentBroker.cpp | 7 ++++++-
loolwsd/TileCache.cpp | 30 +++++++++++++++++++++++-------
loolwsd/TileCache.hpp | 2 +-
3 files changed, 30 insertions(+), 9 deletions(-)
New commits:
commit 6bf643183e4a93dcb85546f146c364b9f0621a83
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Sep 19 22:16:45 2016 -0400
loolwsd: cancel subscriber tiles only
Change-Id: I207f2332520f29308a2994769aa3a12ea5178477
Reviewed-on: https://gerrit.libreoffice.org/29118
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index a54483c..a30b371 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -569,7 +569,12 @@ void DocumentBroker::cancelTileRequests(const std::shared_ptr<ClientSession>& se
{
std::unique_lock<std::mutex> lock(_mutex);
- tileCache().cancelTiles(session);
+ const auto canceltiles = tileCache().cancelTiles(session);
+ if (!canceltiles.empty())
+ {
+ Log::debug() << "Forwarding canceltiles request: " << canceltiles << Log::end;
+ _childProcess->getWebSocket()->sendFrame(canceltiles.data(), canceltiles.size());
+ }
}
void DocumentBroker::handleTileResponse(const std::vector<char>& payload)
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 1ad4907..a5f7c0f 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -475,26 +475,42 @@ int TileCache::subscribeToTileRendering(const TileDesc& tile, const std::shared_
}
}
-void TileCache::cancelTiles(const std::shared_ptr<ClientSession> &subscriber)
+std::string TileCache::cancelTiles(const std::shared_ptr<ClientSession> &subscriber)
{
std::unique_lock<std::mutex> lock(_tilesBeingRenderedMutex);
const auto sub = subscriber.get();
Log::trace("Cancelling tiles for " + subscriber->getName());
+ std::ostringstream oss;
for (auto it = _tilesBeingRendered.begin(); it != _tilesBeingRendered.end(); )
{
auto& subscribers = it->second->_subscribers;
Log::trace("Tile " + it->first + " has " + std::to_string(subscribers.size()) + " subscribers.");
- subscribers.erase(std::remove_if(subscribers.begin(), subscribers.end(),
- [sub](std::weak_ptr<ClientSession>& ptr){ return ptr.lock().get() == sub; }),
- subscribers.end());
- Log::trace(" Tile " + it->first + " has " + std::to_string(subscribers.size()) + " subscribers.");
- // Remove if there are no more subscribers on this tile.
- it = (subscribers.empty() ? _tilesBeingRendered.erase(it) : ++it);
+ const auto itRem = std::find_if(subscribers.begin(), subscribers.end(),
+ [sub](std::weak_ptr<ClientSession>& ptr){ return ptr.lock().get() == sub; });
+ if (itRem != subscribers.end())
+ {
+ Log::trace("Tile " + it->first + " has " + std::to_string(subscribers.size()) + " subscribers. Removing one.");
+ subscribers.erase(itRem, itRem + 1);
+ if (subscribers.empty())
+ {
+ // No other subscriber, remove it from the render queue.
+ oss << it->second->getVersion() << ',';
+ it = _tilesBeingRendered.erase(it);
+ }
+ }
+
+ if (!subscribers.empty())
+ {
+ ++it;
+ }
}
+
+ const auto canceltiles = oss.str();
+ return (canceltiles.empty() ? canceltiles : "canceltiles " + canceltiles);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 2801e22..6d206fc 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -43,7 +43,7 @@ public:
int subscribeToTileRendering(const TileDesc& tile, const std::shared_ptr<ClientSession> &subscriber);
/// Cancels all tile requests by the given subscriber.
- void cancelTiles(const std::shared_ptr<ClientSession> &subscriber);
+ std::string cancelTiles(const std::shared_ptr<ClientSession> &subscriber);
std::unique_ptr<std::fstream> lookupTile(const TileDesc& tile);
More information about the Libreoffice-commits
mailing list