net/WebSocketHandler.cpp | 12 ------------ net/WebSocketHandler.hpp | 35 +++++++++++++---------------------- test/Makefile.am | 1 - wsd/LOOLWSD.cpp | 16 ++++++++-------- 4 files changed, 21 insertions(+), 43 deletions(-)
New commits: commit 01885dc81aafd7613896b801567909285d9cfa9b Author: Jan Holesovsky <ke...@collabora.com> Date: Wed Mar 1 19:49:29 2017 +0100 nb: No need for the WebSocketSender I think. Change-Id: I133bb8341a846d70f95e0c70274541b5db62f65d diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp index 3b5756d..b55c4f2 100644 --- a/net/WebSocketHandler.hpp +++ b/net/WebSocketHandler.hpp @@ -33,6 +33,12 @@ public: { } + WebSocketHandler(const std::weak_ptr<StreamSocket>& socket) : + _shuttingDown(false) + { + onConnect(socket); + } + /// Implementation of the SocketHandlerInterface. void onConnect(const std::weak_ptr<StreamSocket>& socket) override { @@ -193,6 +199,11 @@ public: _wsPayload.clear(); } + void sendFrame(const std::string& msg) const + { + sendMessage(msg.data(), msg.size(), WSOpCode::Text); + } + /// Sends a WebSocket message of WPOpCode type. /// Returns the number of bytes written (including frame overhead) on success, /// 0 for closed/invalid socket, and -1 for other errors. @@ -274,29 +285,9 @@ protected: return len + 2; } - /// To me overriden to handle the websocket messages the way you need. - virtual void handleMessage(bool fin, WSOpCode code, std::vector<char> &data) = 0; -}; - -class WebSocketSender : private WebSocketHandler -{ -public: - WebSocketSender(const std::weak_ptr<StreamSocket>& socket) - { - onConnect(socket); - } - - void sendFrame(const std::string& msg) const - { - sendMessage(msg.data(), msg.size(), WSOpCode::Text); - } - - using WebSocketHandler::shutdown; - -private: - void handleMessage(bool, WSOpCode, std::vector<char>&) override + /// To be overriden to handle the websocket messages the way you need. + virtual void handleMessage(bool /*fin*/, WSOpCode /*code*/, std::vector<char> &/*data*/) { - // We will not read any. } }; diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 2985b25..73f5454 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -204,7 +204,7 @@ static int careerSpanSeconds = 0; namespace { -inline void shutdownLimitReached(WebSocketSender& ws) +inline void shutdownLimitReached(WebSocketHandler& ws) { const std::string error = Poco::format(PAYLOAD_UNAVAILABLE_LIMIT_REACHED, MAX_DOCUMENTS, MAX_CONNECTIONS); LOG_INF("Sending client limit-reached message: " << error); @@ -2340,7 +2340,7 @@ bool LOOLWSD::createForKit() std::mutex Connection::Mutex; #endif -static std::shared_ptr<DocumentBroker> createDocBroker(WebSocketSender& ws, +static std::shared_ptr<DocumentBroker> createDocBroker(WebSocketHandler& ws, const std::string& uri, const std::string& docKey, const Poco::URI& uriPublic) @@ -2378,7 +2378,7 @@ static std::shared_ptr<DocumentBroker> createDocBroker(WebSocketSender& ws, /// Otherwise, creates and adds a new one to DocBrokers. /// May return null if terminating or MaxDocuments limit is reached. /// After returning a valid instance DocBrokers must be cleaned up after exceptions. -static std::shared_ptr<DocumentBroker> findOrCreateDocBroker(WebSocketSender& ws, +static std::shared_ptr<DocumentBroker> findOrCreateDocBroker(WebSocketHandler& ws, const std::string& uri, const std::string& docKey, const std::string& id, @@ -2514,7 +2514,7 @@ static void removeDocBrokerSession(const std::shared_ptr<DocumentBroker>& docBro } } -static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketSender& ws, +static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHandler& ws, const std::string& id, const Poco::URI& uriPublic, const std::shared_ptr<DocumentBroker>& docBroker, @@ -3125,7 +3125,7 @@ private: LOG_INF("Client WS request" << request.getURI() << ", url: " << url); // First Upgrade. - WebSocketSender ws = upgradeToWebSocket(request); + WebSocketHandler ws = upgradeToWebSocket(request); if (_connectionNum > MAX_CONNECTIONS) { @@ -3206,7 +3206,7 @@ private: LOG_CHECK_RET(docBroker && "Null DocumentBroker instance", ); const auto docKey = docBroker->getDocKey(); - WebSocketSender ws(_socket); + WebSocketHandler ws(_socket); try { // Connection terminated. Destroy session. @@ -3282,7 +3282,7 @@ private: } /// Upgrade the http(s) connection to a websocket. - WebSocketSender upgradeToWebSocket(const Poco::Net::HTTPRequest& req) + WebSocketHandler upgradeToWebSocket(const Poco::Net::HTTPRequest& req) { LOG_TRC("Upgrading to WebSocket"); assert(_wsState == WSState::HTTP); @@ -3309,7 +3309,7 @@ private: _wsState = WSState::WS; // Create a WS wrapper to use for sending the client status. - return WebSocketSender(socket); + return WebSocketHandler(socket); } /// To make the protected 'computeAccept' accessible. commit 76e029a25ddfaa73d51b820d31e60b926c83a635 Author: Jan Holesovsky <ke...@collabora.com> Date: Wed Mar 1 19:10:17 2017 +0100 nb: This file is not needed any more. Change-Id: Ic73ddcc61495889fd36eb6f23f41c1bd45eb85c6 diff --git a/net/WebSocketHandler.cpp b/net/WebSocketHandler.cpp deleted file mode 100644 index 8390704..0000000 --- a/net/WebSocketHandler.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include "WebSocketHandler.hpp" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/Makefile.am b/test/Makefile.am index 167c436..d849f13 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -36,7 +36,6 @@ wsd_sources = \ ../common/Protocol.cpp \ ../common/Session.cpp \ ../common/MessageQueue.cpp \ - ../net/WebSocketHandler.cpp \ ../kit/Kit.cpp \ ../wsd/TileCache.cpp \ ../common/Unit.cpp \ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits