loolwsd/IoUtil.cpp | 24 ------------------------ loolwsd/IoUtil.hpp | 8 +------- loolwsd/LOOLForKit.cpp | 33 ++++++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 40 deletions(-)
New commits: commit 882ffafb16e01ac8bfd8cfefd8c5fc03e98d6f90 Author: Ashod Nakashian <[email protected]> Date: Sun Apr 17 12:05:56 2016 -0400 loolwsd: simplified ChildDispatcher Change-Id: I5b61678a01f4491ca06a25dd969f7538b4c8445d Reviewed-on: https://gerrit.libreoffice.org/24164 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index f024055..93a61ea 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -321,30 +321,6 @@ int PipeReader::readLine(std::string& line, return 0; } -bool PipeReader::processOnce(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate) -{ - std::string line; - const auto ready = readLine(line, stopPredicate); - if (ready == 0) - { - // Timeout. - return true; - } - else if (ready < 0) - { - Log::error("Error reading from pipe [" + _name + "]."); - return false; - } - else if (!handler(line)) - { - Log::info("Pipe [" + _name + "] handler requested to finish."); - return false; - } - - return true; -} - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp index a9ed2ef..476f515 100644 --- a/loolwsd/IoUtil.hpp +++ b/loolwsd/IoUtil.hpp @@ -50,19 +50,13 @@ namespace IoUtil const std::string& getName() const { return _name; } - /// Processes a single line read and invoking stopPredicate - /// to check for termination condition. - /// Intended to be called from a polling loop. - bool processOnce(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate); - - private: /// Reads a single line from the pipe. /// Returns 0 for timeout, <0 for error, and >0 on success. /// On success, line will contain the read message. int readLine(std::string& line, std::function<bool()> stopPredicate); + private: const std::string _name; const int _pipe; std::string _data; diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index 4d7ba5f..a6fd559 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -52,19 +52,37 @@ int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER; static int pipeFd = -1; -class ChildDispatcher +class ChildDispatcher : public IoUtil::PipeReader { public: - ChildDispatcher() : - _wsdPipeReader("wsd_pipe_rd", pipeFd) + ChildDispatcher(const int pipeFd) : + PipeReader("wsd_pipe_rd", pipeFd) { } /// Polls WSD commands and dispatches them to the appropriate child. bool pollAndDispatch() { - return _wsdPipeReader.processOnce([this](std::string& message) { handleInput(message); return true; }, - []() { return TerminationFlag; }); + std::string line; + const auto ready = readLine(line, [](){ return TerminationFlag; }); + if (ready == 0) + { + // Timeout. + return true; + } + else if (ready < 0) + { + // Termination is done via SIGINT, which breaks the wait. + if (!TerminationFlag) + { + Log::error("Error reading from pipe [" + getName() + "]."); + } + + return false; + } + + handleInput(line); + return true; } private: @@ -88,9 +106,6 @@ private: } } } - -private: - IoUtil::PipeReader _wsdPipeReader; }; static int createLibreOfficeKit(const std::string& childRoot, @@ -264,7 +279,7 @@ int main(int argc, char** argv) std::exit(Application::EXIT_SOFTWARE); } - ChildDispatcher childDispatcher; + ChildDispatcher childDispatcher(pipeFd); Log::info("ForKit process is ready."); while (!TerminationFlag) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
