loolwsd/DocumentBroker.cpp | 8 ++++---- loolwsd/LOOLKit.cpp | 31 +++++++++++++++++++++++-------- loolwsd/test/TileCacheTests.cpp | 14 -------------- loolwsd/test/helpers.hpp | 14 ++++++++++++++ 4 files changed, 41 insertions(+), 26 deletions(-)
New commits: commit f4d72d66e3676249581b7f69e89c01eecd6ce922 Author: Ashod Nakashian <[email protected]> Date: Sat Nov 5 17:25:39 2016 -0400 loolwsd: move genRandomData to helpers Change-Id: I1edafb41fefc07e64fa8625d2b88617079a327fa Reviewed-on: https://gerrit.libreoffice.org/30622 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/test/TileCacheTests.cpp b/loolwsd/test/TileCacheTests.cpp index 3618f19..ade2ae0 100644 --- a/loolwsd/test/TileCacheTests.cpp +++ b/loolwsd/test/TileCacheTests.cpp @@ -112,20 +112,6 @@ class TileCacheTests : public CPPUNIT_NS::TestFixture void checkBlackTile(std::stringstream& tile); - static - std::vector<char> genRandomData(const size_t size) - { - std::vector<char> v(size); - v.resize(size); - auto data = v.data(); - for (size_t i = 0; i < size; ++i) - { - data[i] = static_cast<char>(Util::rng::getNext()); - } - - return v; - } - public: TileCacheTests() : _uri(helpers::getTestServerURI()) diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp index 1a386ba..ace1f32 100644 --- a/loolwsd/test/helpers.hpp +++ b/loolwsd/test/helpers.hpp @@ -55,6 +55,20 @@ namespace helpers { inline +std::vector<char> genRandomData(const size_t size) +{ + std::vector<char> v(size); + v.resize(size); + auto data = v.data(); + for (size_t i = 0; i < size; ++i) + { + data[i] = static_cast<char>(Util::rng::getNext()); + } + + return v; +} + +inline std::vector<char> readDataFromFile(const std::string& filename) { std::ifstream ifs(Poco::Path(TDOC, filename).toString(), std::ios::binary); commit 0305cf4819abd6681cc40cbbffff6f74f8a0c1e9 Author: Ashod Nakashian <[email protected]> Date: Sat Nov 5 16:22:07 2016 -0400 loolwsd: more efficient child message forwarding Change-Id: I60ab308b2f7d108ee9e4f2892fe3dda68f7f3201 Reviewed-on: https://gerrit.libreoffice.org/30621 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index 754b836..5d187b8 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -868,7 +868,7 @@ bool DocumentBroker::forwardToClient(const std::string& prefix, const std::vecto auto data = payload.data() + index; auto size = payload.size() - index; const auto message = getAbbreviatedMessage(data, size); - Log::trace("Forwarding payload to " + prefix + ' ' + message); + LOG_TRC("Forwarding payload to " << prefix << ' ' << message); std::string name; std::string sid; @@ -884,17 +884,17 @@ bool DocumentBroker::forwardToClient(const std::string& prefix, const std::vecto } else { - Log::warn() << "Client session [" << sid << "] has no peer to forward message: " << message << Log::end; + LOG_WRN("Client session [" << sid << "] has no peer to forward message: " << message); } } else { - Log::warn() << "Client session [" << sid << "] not found to forward message: " << message << Log::end; + LOG_WRN("Client session [" << sid << "] not found to forward message: " << message); } } else { - Log::error("Failed to parse prefix of forward-to-client message: " + message); + LOG_ERR("Failed to parse prefix of forward-to-client message: " << prefix); } return false; diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index acdc2e5..75f2f87 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1117,9 +1117,22 @@ private: bool forwardToChild(const std::string& prefix, const std::vector<char>& payload) { - std::string message(payload.data() + prefix.size(), payload.size() - prefix.size()); - Util::ltrim(message); - Log::trace("Forwarding payload to " + prefix + ' ' + message); + assert(payload.size() > prefix.size()); + + // Remove the prefix and trim. + size_t index = prefix.size(); + for ( ; index < payload.size(); ++index) + { + if (payload[index] != ' ') + { + break; + } + } + + auto data = payload.data() + index; + auto size = payload.size() - index; + const auto abbrMessage = getAbbreviatedMessage(data, size); + LOG_TRC("Forwarding payload to " << prefix << ' ' << abbrMessage); std::string name; std::string sessionId; @@ -1128,9 +1141,11 @@ private: const auto it = _sessions.find(sessionId); if (it != _sessions.end()) { - if (message == "disconnect") + static const std::string disconnect("disconnect"); + if (size == disconnect.size() && + strncmp(data, disconnect.data(), disconnect.size()) == 0) { - Log::debug("Removing ChildSession " + sessionId); + LOG_DBG("Removing ChildSession " << sessionId); _oldSessionIds[it->second->getViewId()] = UserInfo({it->second->getViewUserId(), it->second->getViewUserName()}); _sessions.erase(it); return true; @@ -1139,15 +1154,15 @@ private: auto session = it->second; if (session) { - return session->handleInput(message.data(), message.size()); + return session->handleInput(data, size); } } - Log::warn() << "Child session [" << sessionId << "] not found to forward message: " << message << Log::end; + LOG_WRN("Child session [" << sessionId << "] not found to forward message: " << abbrMessage); } else { - Log::error("Failed to parse prefix of forward-to-child message: " + message); + LOG_ERR("Failed to parse prefix of forward-to-child message: " << prefix); } return false; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
