[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun Oct 16 22:04:15 UTC 2016
loolwsd/DocumentBroker.cpp | 12 ++++++------
loolwsd/DocumentBroker.hpp | 19 ++++++++++++++++++-
2 files changed, 24 insertions(+), 7 deletions(-)
New commits:
commit 75c99ed9b6939f9ee0be68cec2d82572d63ac48c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Tue Oct 11 18:22:51 2016 -0400
loolwsd: cleanup child process WS interface
Change-Id: I30d74fc25434301145da292711fe5e33972ac876
Reviewed-on: https://gerrit.libreoffice.org/29936
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 c562048..adadee2 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -405,7 +405,7 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session)
// Request a new session from the child kit.
Log::debug("DocBroker to Child: " + aMessage.substr(0, aMessage.length() - 1));
- _childProcess->getWebSocket()->sendFrame(aMessage.data(), aMessage.size());
+ _childProcess->sendTextFrame(aMessage);
auto ret = _sessions.emplace(id, session);
if (!ret.second)
@@ -454,7 +454,7 @@ size_t DocumentBroker::removeSession(const std::string& id)
// Let the child know the client has disconnected.
const std::string msg("child-" + id + " disconnect");
- _childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+ _childProcess->sendTextFrame(msg);
}
return _sessions.size();
@@ -561,7 +561,7 @@ void DocumentBroker::handleTileRequest(TileDesc& tile,
// Forward to child to render.
Log::debug() << "Sending render request for tile (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ")." << Log::end;
const std::string request = "tile " + tile.serialize();
- _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+ _childProcess->sendTextFrame(request);
_debugRenderedTileCount++;
}
@@ -620,7 +620,7 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
// Forward to child to render.
const auto req = newTileCombined.serialize("tilecombine");
Log::debug() << "Sending residual tilecombine: " << req << Log::end;
- _childProcess->getWebSocket()->sendFrame(req.data(), req.size());
+ _childProcess->sendTextFrame(req);
}
}
@@ -632,7 +632,7 @@ void DocumentBroker::cancelTileRequests(const std::shared_ptr<ClientSession>& se
if (!canceltiles.empty())
{
Log::debug() << "Forwarding canceltiles request: " << canceltiles << Log::end;
- _childProcess->getWebSocket()->sendFrame(canceltiles.data(), canceltiles.size());
+ _childProcess->sendTextFrame(canceltiles);
}
}
@@ -748,7 +748,7 @@ bool DocumentBroker::forwardToChild(const std::string& viewId, const char *buffe
{
const auto msg = "child-" + viewId + ' ' + message;
Log::debug("DocBroker to Child: " + msg);
- _childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+ _childProcess->sendTextFrame(msg);
return true;
}
else
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index a1aa06d..5d0b414 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -87,7 +87,24 @@ public:
}
Poco::Process::PID getPid() const { return _pid; }
- std::shared_ptr<Poco::Net::WebSocket> getWebSocket() const { return _ws; }
+
+ /// Send a text payload to the child-process WS.
+ bool sendTextFrame(const std::string& data)
+ {
+ try
+ {
+ _ws->sendFrame(data.data(), data.size());
+ return true;
+ }
+ catch (const std::exception& exc)
+ {
+ Log::error() << "Failed to send child [" << _pid << "] data ["
+ << data << "] due to: " << exc.what() << Log::end;
+ throw;
+ }
+
+ return false;
+ }
/// Check whether this child is alive and able to respond.
bool isAlive() const
More information about the Libreoffice-commits
mailing list