loolwsd/Common.hpp | 5 ----- loolwsd/DocumentBroker.hpp | 2 ++ loolwsd/LOOLKit.cpp | 30 ++++-------------------------- loolwsd/LOOLSession.cpp | 17 ++--------------- loolwsd/Util.cpp | 20 ++++++++++++++++++++ loolwsd/Util.hpp | 10 ++++++++++ 6 files changed, 38 insertions(+), 46 deletions(-)
New commits: commit 5f6858f7821471bd188764d52a84df39376e742e Author: Jan Holesovsky <[email protected]> Date: Tue Nov 8 18:19:15 2016 +0100 Factor out creation of nextmessage: and improve its logging. Change-Id: I552bc2599835b4f6c9d4ef423889b464c5701221 diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp index cfe0e2d..686b556 100644 --- a/loolwsd/Common.hpp +++ b/loolwsd/Common.hpp @@ -27,11 +27,6 @@ constexpr int WS_SEND_TIMEOUT_MS = 1000; /// Should be large enough for ethernet packets /// which can be 1500 bytes long. constexpr int READ_BUFFER_SIZE = 2048; -/// Size after which messages will be sent preceded with -/// 'nextmessage' frame to let the receiver know in advance -/// the size of larger coming message. All messages up to this -/// size are considered small messages. -constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2; constexpr auto JAILED_DOCUMENT_ROOT = "/user/docs/"; constexpr auto CHILD_URI = "/loolws/child?"; diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index 34195c9..2b0f162 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -150,6 +150,8 @@ public: { // We don't care about the response (and shouldn't read here). _ws->sendFrame("PING", 4, Poco::Net::WebSocket::FRAME_OP_PING); + LOG_DBG("Sent a PING."); + return true; } } diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index c97f247..52510ab 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -504,15 +504,8 @@ public: return; } - const auto length = output.size(); - if (length > SMALL_MESSAGE_SIZE) - { - const std::string nextmessage = "nextmessage: size=" + std::to_string(length); - ws->sendFrame(nextmessage.data(), nextmessage.size()); - } - - LOG_TRC("Sending render-tile response (" << length << " bytes) for: " << response); - ws->sendFrame(output.data(), length, WebSocket::FRAME_BINARY); + LOG_TRC("Sending render-tile response (" + std::to_string(output.size()) + " bytes) for: " + response); + Util::sendLargeFrame(ws, output, WebSocket::FRAME_BINARY); } void renderCombinedTiles(StringTokenizer& tokens, const std::shared_ptr<Poco::Net::WebSocket>& ws) @@ -612,14 +605,7 @@ public: std::copy(tileMsg.begin(), tileMsg.end(), response.begin()); std::copy(output.begin(), output.end(), response.begin() + tileMsg.size()); - const auto length = response.size(); - if (length > SMALL_MESSAGE_SIZE) - { - const std::string nextmessage = "nextmessage: size=" + std::to_string(length); - ws->sendFrame(nextmessage.data(), nextmessage.size()); - } - - ws->sendFrame(response.data(), length, WebSocket::FRAME_BINARY); + Util::sendLargeFrame(ws, response, WebSocket::FRAME_BINARY); } bool sendTextFrame(const std::string& message) override @@ -632,15 +618,7 @@ public: return false; } - const auto length = message.size(); - if (length > SMALL_MESSAGE_SIZE) - { - const std::string nextmessage = "nextmessage: size=" + std::to_string(length); - LOG_TRC("Sending large message [" << nextmessage << "]."); - _ws->sendFrame(nextmessage.data(), nextmessage.size()); - } - - _ws->sendFrame(message.data(), length); + Util::sendLargeFrame(_ws, message.data(), message.size()); return true; } catch (const Exception& exc) diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index d671066..c281adc 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -84,14 +84,7 @@ bool LOOLSession::sendTextFrame(const char* buffer, const int length) return false; } - if (length > SMALL_MESSAGE_SIZE) - { - const std::string nextmessage = "nextmessage: size=" + std::to_string(length); - LOG_TRC("Sending large message [" << nextmessage << "]."); - _ws->sendFrame(nextmessage.data(), nextmessage.size()); - } - - _ws->sendFrame(buffer, length); + Util::sendLargeFrame(_ws, buffer, length); return true; } catch (const Exception& exc) @@ -116,13 +109,7 @@ bool LOOLSession::sendBinaryFrame(const char *buffer, int length) return false; } - if (length > SMALL_MESSAGE_SIZE) - { - const std::string nextmessage = "nextmessage: size=" + std::to_string(length); - _ws->sendFrame(nextmessage.data(), nextmessage.size()); - } - - _ws->sendFrame(buffer, length, WebSocket::FRAME_BINARY); + Util::sendLargeFrame(_ws, buffer, length, WebSocket::FRAME_BINARY); return true; } catch (const Exception& exc) diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index 1b9a63c..deaee45 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -46,6 +46,7 @@ #include <Poco/Util/Application.h> #include "Common.hpp" +#include "LOOLProtocol.hpp" #include "Log.hpp" #include "Util.hpp" @@ -563,6 +564,25 @@ namespace Util static std::atomic_int counter(0); return std::to_string(Poco::Process::id()) + "/" + std::to_string(counter++); } + + void sendLargeFrame(const std::shared_ptr<Poco::Net::WebSocket>& ws, const char *message, int length, int flags) + { + // Size after which messages will be sent preceded with + // 'nextmessage' frame to let the receiver know in advance + // the size of larger coming message. All messages up to this + // size are considered small messages. + constexpr int SMALL_MESSAGE_SIZE = READ_BUFFER_SIZE / 2; + + if (length > SMALL_MESSAGE_SIZE) + { + const std::string nextmessage = "nextmessage: size=" + std::to_string(length); + ws->sendFrame(nextmessage.data(), nextmessage.size()); + Log::debug("Message is long, sent " + nextmessage); + } + + ws->sendFrame(message, length, flags); + Log::debug("Sent frame: " + LOOLProtocol::getAbbreviatedMessage(std::string(message, length))); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index cde7828..462d542 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -178,6 +178,16 @@ namespace Util return s; } + /// Send frame. If it is too long, send a 'nextmessage:' before the real + /// frame. + void sendLargeFrame(const std::shared_ptr<Poco::Net::WebSocket>& ws, const char *message, int length, int flags = Poco::Net::WebSocket::FRAME_TEXT); + + /// Send frame as above, the std::string variant. + inline void sendLargeFrame(const std::shared_ptr<Poco::Net::WebSocket>& ws, const std::vector<char> &message, int flags = Poco::Net::WebSocket::FRAME_TEXT) + { + sendLargeFrame(ws, message.data(), message.size(), flags); + } + /// Given one or more patterns to allow, and one or more to deny, /// the match member will return true if, and only if, the subject /// matches the allowed list, but not the deny. _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
