Store sent tiles's id instead of using a simple counter

Change-Id: I8cbf84923a53fb6b294bd4039eb7382326f8c445
This commit is contained in:
Tamás Zolnai 2018-06-13 15:04:09 +02:00
parent 464dd72e1c
commit 85f96bc281
5 changed files with 36 additions and 20 deletions

View file

@ -1435,7 +1435,8 @@ L.TileLayer = L.GridLayer.extend({
L.Log.log(textMsg, L.INCOMING, key);
// Send acknowledgment, that the tile message arrived
this._map._socket.sendMessage('tileprocessed tile= ' + key);
var tileID = command.part + ':' + command.x + ':' + command.y + ':' + command.tileWidth + ':' + command.tileHeight;
this._map._socket.sendMessage('tileprocessed tile=' + tileID);
},
_tileOnLoad: function (done, tile) {

View file

@ -12,6 +12,7 @@
#include "ClientSession.hpp"
#include <fstream>
#include <sstream>
#include <Poco/File.h>
#include <Poco/Net/HTTPResponse.h>
@ -54,8 +55,7 @@ ClientSession::ClientSession(const std::string& id,
_tileWidthPixel(0),
_tileHeightPixel(0),
_tileWidthTwips(0),
_tileHeightTwips(0),
_tilesOnFly(0)
_tileHeightTwips(0)
{
assert(!creatingPngThumbnail || thumbnailFile != "");
const size_t curConnections = ++LOOLWSD::NumConnections;
@ -335,13 +335,20 @@ bool ClientSession::_handleInput(const char *buffer, int length)
}
else if (tokens[0] == "tileprocessed")
{
if(_tilesOnFly > 0) // canceltiles message can zero this value
std::string tileID;
if (tokens.size() != 2 ||
!getTokenString(tokens[1], "tile", tileID))
{
--_tilesOnFly;
if(_tilesOnFly == 0)
{
_tileCounterStartTime = boost::none;
}
sendTextFrame("error: cmd=tileprocessed kind=syntax");
return false;
}
auto iter = std::find(_tilesOnFly.begin(), _tilesOnFly.end(), tileID);
if(iter != _tilesOnFly.end())
_tilesOnFly.erase(iter);
if(_tilesOnFly.empty())
{
_tileCounterStartTime = boost::none;
}
docBroker->sendRequestedTiles(shared_from_this());
return true;
@ -1048,15 +1055,23 @@ Authorization ClientSession::getAuthorization() const
return Authorization();
}
void ClientSession::setTilesOnFly(int tilesOnFly)
void ClientSession::setTilesOnFly(boost::optional<TileCombined> tiles)
{
_tilesOnFly = tilesOnFly;
if(tilesOnFly == 0)
_tilesOnFly.clear();
if(tiles == boost::none)
{
_tileCounterStartTime = boost::none;
}
else
{
for (auto& tile : tiles.get().getTiles())
{
std::ostringstream tileID;
tileID << tile.getPart() << ":" << tile.getTilePosX() << ":" << tile.getTilePosY() << ":"
<< tile.getTileWidth() << ":" << tile.getTileHeight();
_tilesOnFly.push_back(tileID.str());
}
_tileCounterStartTime = std::chrono::steady_clock::now();
}
}

View file

@ -18,6 +18,7 @@
#include <Poco/URI.h>
#include <Rectangle.hpp>
#include <boost/optional.hpp>
#include <vector>
class DocumentBroker;
@ -111,8 +112,8 @@ public:
boost::optional<TileCombined>& getRequestedTiles() { return _requestedTiles; }
int getTilesOnFly() const { return _tilesOnFly; }
void setTilesOnFly(int tilesOnFly);
const std::vector<std::string>& getTilesOnFly() const { return _tilesOnFly; }
void setTilesOnFly(boost::optional<TileCombined> tiles);
private:
@ -206,7 +207,7 @@ private:
// Type of the docuemnt, extracter from status message
std::string _docType;
int _tilesOnFly;
std::vector<std::string> _tilesOnFly;
boost::optional<std::chrono::time_point<std::chrono::steady_clock>> _tileCounterStartTime;
boost::optional<TileCombined> _requestedTiles;

View file

@ -1363,15 +1363,14 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
void DocumentBroker::sendRequestedTiles(const std::shared_ptr<ClientSession>& session)
{
assert(session->getTilesOnFly() >= 0);
std::unique_lock<std::mutex> lock(_mutex);
// All tiles were processed on client side what we sent last time, so we can send a new banch of tiles
// which was invalidated / requested in the meantime
boost::optional<TileCombined>& requestedTiles = session->getRequestedTiles();
if(session->getTilesOnFly() == 0 && requestedTiles != boost::none && !requestedTiles.get().getTiles().empty())
if(session->getTilesOnFly().empty() && requestedTiles != boost::none && !requestedTiles.get().getTiles().empty())
{
session->setTilesOnFly(requestedTiles.get().getTiles().size());
session->setTilesOnFly(requestedTiles.get());
// Satisfy as many tiles from the cache.
std::vector<TileDesc> tilesNeedsRendering;
@ -1436,7 +1435,7 @@ void DocumentBroker::cancelTileRequests(const std::shared_ptr<ClientSession>& se
std::unique_lock<std::mutex> lock(_mutex);
// Clear tile requests
session->setTilesOnFly(0);
session->setTilesOnFly(boost::none);
session->getRequestedTiles() = boost::none;
const std::string canceltiles = tileCache().cancelTiles(session);

View file

@ -34,7 +34,7 @@ canceltiles
tileprocessed tile=<tileid>
Previously sent tile (server -> client) arrived and processed by the client.
Tileid has the next stucture : <tile x coord>:<tile y coord>:<zoom level>:<selected part>
Tileid has the next stucture : <selected part>:<tile x coord>:<tile y coord>:<tile width in twips>:<tile height in twips>
downloadas name=<fileName> id=<id> format=<document format> options=<SkipImages, etc>