[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/test loolwsd/TileCache.cpp loolwsd/TileCache.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri Sep 23 02:14:07 UTC 2016
loolwsd/DocumentBroker.cpp | 20 +++++++++++---------
loolwsd/TileCache.cpp | 15 +++++++++------
loolwsd/TileCache.hpp | 2 +-
loolwsd/test/TileCacheTests.cpp | 2 +-
4 files changed, 22 insertions(+), 17 deletions(-)
New commits:
commit 01718c5c68bad8d324dfcc1b93d3c49055c90873
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Sep 22 17:47:12 2016 -0400
loolwsd: TileCache is told to save or not before notifying subscribers
Change-Id: Ibe24bbe9b4bf6fbaae7c9fcea5f919f7091d299e
Reviewed-on: https://gerrit.libreoffice.org/29207
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 989e056..c241594 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -587,14 +587,15 @@ void DocumentBroker::handleTileResponse(const std::vector<char>& payload)
try
{
auto tile = TileDesc::parse(firstLine);
- const auto buffer = payload.data();
- const auto length = payload.size();
+
+ const auto length = payload.size();
if (firstLine.size() < static_cast<std::string::size_type>(length) - 1)
{
- tileCache().saveTileAndNotify(
+ const auto buffer = payload.data();
+ tileCache().notifySubscribers(
tile, buffer + firstLine.size() + 1,
- length - firstLine.size() - 1);
+ length - firstLine.size() - 1, true);
}
else
{
@@ -619,21 +620,22 @@ void DocumentBroker::handleTileCombinedResponse(const std::vector<char>& payload
try
{
auto tileCombined = TileCombined::parse(firstLine);
- const auto buffer = payload.data();
- const auto length = payload.size();
- auto offset = firstLine.size() + 1;
+
+ const auto length = payload.size();
if (firstLine.size() < static_cast<std::string::size_type>(length) - 1)
{
+ const auto buffer = payload.data();
+ auto offset = firstLine.size() + 1;
for (const auto& tile : tileCombined.getTiles())
{
- tileCache().saveTileAndNotify(tile, buffer + offset, tile.getImgSize());
+ tileCache().notifySubscribers(tile, buffer + offset, tile.getImgSize(), true);
offset += tile.getImgSize();
}
}
else
{
- Log::error() << "Render request failed for " << firstLine << Log::end;
+ Log::debug() << "Render request declined for " << firstLine << Log::end;
std::unique_lock<std::mutex> tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
for (const auto& tile : tileCombined.getTiles())
{
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index d13400e..acaf18b 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -143,7 +143,7 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(const TileDesc& tile)
return nullptr;
}
-void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const size_t size)
+void TileCache::notifySubscribers(const TileDesc& tile, const char *data, const size_t size, const bool save)
{
std::unique_lock<std::mutex> lock(_tilesBeingRenderedMutex);
@@ -152,11 +152,14 @@ void TileCache::saveTileAndNotify(const TileDesc& tile, const char *data, const
// Save to disk.
const auto cachedName = (tileBeingRendered ? tileBeingRendered->getCacheName()
: cacheFileName(tile));
- const auto fileName = _cacheDir + "/" + cachedName;
- Log::trace() << "Saving cache tile: " << fileName << Log::end;
- std::fstream outStream(fileName, std::ios::out);
- outStream.write(data, size);
- outStream.close();
+ if (save)
+ {
+ const auto fileName = _cacheDir + "/" + cachedName;
+ Log::trace() << "Saving cache tile: " << fileName << Log::end;
+ std::fstream outStream(fileName, std::ios::out);
+ outStream.write(data, size);
+ outStream.close();
+ }
// Notify subscribers, if any.
if (tileBeingRendered)
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index fc0210b..206603b 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -47,7 +47,7 @@ public:
std::unique_ptr<std::fstream> lookupTile(const TileDesc& tile);
- void saveTileAndNotify(const TileDesc& tile, const char *data, const size_t size);
+ void notifySubscribers(const TileDesc& tile, const char *data, const size_t size, const bool save);
std::string getTextFile(const std::string& fileName);
diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp
index f2d7f3d..9081675 100644
--- a/loolwsd/test/TileCacheTests.cpp
+++ b/loolwsd/test/TileCacheTests.cpp
@@ -167,7 +167,7 @@ void TileCacheTests::testSimple()
// Cache Tile
const auto size = 1024;
const auto data = genRandomData(size);
- tc.saveTileAndNotify(tile, data.data(), size);
+ tc.notifySubscribers(tile, data.data(), size, true);
// Find Tile
file = tc.lookupTile(tile);
More information about the Libreoffice-commits
mailing list