loolwsd/IoUtil.cpp | 19 +++++++++++++++++++ loolwsd/IoUtil.hpp | 10 ++++++++++ loolwsd/LOOLKit.cpp | 6 +++--- loolwsd/LOOLSession.cpp | 4 ++-- loolwsd/Util.cpp | 20 -------------------- loolwsd/Util.hpp | 10 ---------- 6 files changed, 34 insertions(+), 35 deletions(-)
New commits: commit 024a6048a0d4d6b6c84a5e0bb325d44b41abe9ad Author: Jan Holesovsky <ke...@collabora.com> Date: Tue Nov 8 19:57:03 2016 +0100 Move sendLargeFrame() from Util to IoUtil. Change-Id: Id5db865b0bcf936651e3c89a0333a101e58ace92 diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index 085422d..321fe40 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -258,6 +258,25 @@ ssize_t readFromPipe(int pipe, char* buffer, ssize_t size) return bytes; } +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))); +} + /// Reads a single line from a pipe. /// Returns 0 for timeout, <0 for error, and >0 on success. /// On success, line will contain the read message. diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp index 564cef5..a23cd33 100644 --- a/loolwsd/IoUtil.hpp +++ b/loolwsd/IoUtil.hpp @@ -44,6 +44,16 @@ namespace IoUtil ssize_t readFromPipe(int pipe, char* buffer, ssize_t size); + /// 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); + } + /// Helper class to handle reading from a pipe. class PipeReader { diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 52510ab..f228be9 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -505,7 +505,7 @@ public: } LOG_TRC("Sending render-tile response (" + std::to_string(output.size()) + " bytes) for: " + response); - Util::sendLargeFrame(ws, output, WebSocket::FRAME_BINARY); + IoUtil::sendLargeFrame(ws, output, WebSocket::FRAME_BINARY); } void renderCombinedTiles(StringTokenizer& tokens, const std::shared_ptr<Poco::Net::WebSocket>& ws) @@ -605,7 +605,7 @@ public: std::copy(tileMsg.begin(), tileMsg.end(), response.begin()); std::copy(output.begin(), output.end(), response.begin() + tileMsg.size()); - Util::sendLargeFrame(ws, response, WebSocket::FRAME_BINARY); + IoUtil::sendLargeFrame(ws, response, WebSocket::FRAME_BINARY); } bool sendTextFrame(const std::string& message) override @@ -618,7 +618,7 @@ public: return false; } - Util::sendLargeFrame(_ws, message.data(), message.size()); + IoUtil::sendLargeFrame(_ws, message.data(), message.size()); return true; } catch (const Exception& exc) diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index c281adc..25bc408 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -84,7 +84,7 @@ bool LOOLSession::sendTextFrame(const char* buffer, const int length) return false; } - Util::sendLargeFrame(_ws, buffer, length); + IoUtil::sendLargeFrame(_ws, buffer, length); return true; } catch (const Exception& exc) @@ -109,7 +109,7 @@ bool LOOLSession::sendBinaryFrame(const char *buffer, int length) return false; } - Util::sendLargeFrame(_ws, buffer, length, WebSocket::FRAME_BINARY); + IoUtil::sendLargeFrame(_ws, buffer, length, WebSocket::FRAME_BINARY); return true; } catch (const Exception& exc) diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index deaee45..1b9a63c 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -46,7 +46,6 @@ #include <Poco/Util/Application.h> #include "Common.hpp" -#include "LOOLProtocol.hpp" #include "Log.hpp" #include "Util.hpp" @@ -564,25 +563,6 @@ 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 462d542..cde7828 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -178,16 +178,6 @@ 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 libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits