loolwsd/LOOLKit.cpp | 2 - loolwsd/LOOLWSD.cpp | 66 +++-------------------------------------------- loolwsd/QueueHandler.hpp | 16 ++++++----- 3 files changed, 15 insertions(+), 69 deletions(-)
New commits: commit f9cfdd902152bde395ce2289b072e19cf1073073 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Wed Jan 6 08:38:21 2016 -0500 loolwsd: reuse QueueHandler Change-Id: I90dd0cc1457604d85ec82c98af9a457f44968b0d Reviewed-on: https://gerrit.libreoffice.org/21161 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index c352422..d468739 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -396,7 +396,7 @@ public: _session->sendTextFrame(hello); TileQueue queue; - QueueHandler handler(queue, _session); + QueueHandler handler(queue, _session, "kit_queue_" + _session->getId()); Thread queueHandlerThread; queueHandlerThread.start(handler); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 259b97e..03dc308 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -108,7 +108,7 @@ DEALINGS IN THE SOFTWARE. #include "MasterProcessSession.hpp" #include "ChildProcessSession.hpp" #include "LOOLWSD.hpp" -#include "MessageQueue.hpp" +#include "QueueHandler.hpp" #include "Util.hpp" using namespace LOOLProtocol; @@ -151,58 +151,6 @@ using Poco::NamedMutex; using Poco::ProcessHandle; using Poco::URI; -class QueueHandler: public Runnable -{ -public: - QueueHandler(MessageQueue& queue): - _queue(queue) - { - } - - void setSession(std::shared_ptr<LOOLSession> session) - { - _session = session; - } - - void run() override - { - static const std::string thread_name = "wsd_queue"; -#ifdef __linux - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); -#endif - Log::debug("Thread [" + thread_name + "] started."); - - try - { - while (true) - { - const std::string input = _queue.get(); - if (input == "eof") - break; - if (!_session->handleInput(input.c_str(), input.size())) - break; - } - } - catch (const std::exception& exc) - { - Log::error(std::string("Exception: ") + exc.what()); - raise(SIGABRT); - } - catch (...) - { - Log::error("Unexpected Exception."); - raise(SIGABRT); - } - - Log::debug("Thread [" + thread_name + "] finished."); - } - -private: - std::shared_ptr<LOOLSession> _session; - MessageQueue& _queue; -}; - /// Handles the filename part of the convert-to POST request payload. class ConvertToPartHandler : public Poco::Net::PartHandler { @@ -473,11 +421,6 @@ public: return; } - BasicTileQueue queue; - Thread queueHandlerThread; - QueueHandler handler(queue); - Poco::Timespan waitTime(POLL_TIMEOUT); - try { auto ws = std::make_shared<WebSocket>(request, response); @@ -488,7 +431,10 @@ public: // For ToClient sessions, we store incoming messages in a queue and have a separate // thread that handles them. This is so that we can empty the queue when we get a // "canceltiles" message. - handler.setSession(session); + BasicTileQueue queue; + QueueHandler handler(queue, session, "wsd_queue_" + session->getId()); + + Thread queueHandlerThread; queueHandlerThread.start(handler); SocketProcessor(ws, response, [&session, &queue](const char* data, const int size, const bool singleLine) @@ -540,8 +486,6 @@ public: #endif Log::debug("Thread [" + thread_name + "] started."); - Poco::Timespan waitTime(POLL_TIMEOUT); - try { auto ws = std::make_shared<WebSocket>(request, response); diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp index 5d07b9a..5111382 100644 --- a/loolwsd/QueueHandler.hpp +++ b/loolwsd/QueueHandler.hpp @@ -18,20 +18,21 @@ class QueueHandler: public Poco::Runnable { public: - QueueHandler(MessageQueue& queue, const std::shared_ptr<LOOLSession>& session): + QueueHandler(MessageQueue& queue, const std::shared_ptr<LOOLSession>& session, + const std::string& name): _queue(queue), - _session(session) + _session(session), + _name(name) { } void run() override { - static const std::string thread_name = "kit_queue_" + _session->getId(); #ifdef __linux - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(_name.c_str()), 0, 0, 0) != 0) + Log::error("Cannot set thread name to " + _name + "."); #endif - Log::debug("Thread [" + thread_name + "] started."); + Log::debug("Thread [" + _name + "] started."); try { @@ -55,12 +56,13 @@ public: raise(SIGABRT); } - Log::debug("Thread [" + thread_name + "] finished."); + Log::debug("Thread [" + _name + "] finished."); } private: MessageQueue& _queue; std::shared_ptr<LOOLSession> _session; + const std::string _name; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits