[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Apr 4 04:05:14 UTC 2016


 loolwsd/LOOLBroker.cpp |   46 ++++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 18 deletions(-)

New commits:
commit 8a318c879a65cdb3285001126b8105b18c7febf5
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Apr 2 17:58:18 2016 -0400

    loolwsd: merged child command dispatching into a single class and renamed
    
    Change-Id: I894849ea7a6c69c084e922c76468c5e9eb621406
    Reviewed-on: https://gerrit.libreoffice.org/23781
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 8c416d1..9df2ef5 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -160,14 +160,35 @@ namespace
     }
 }
 
-class PipeRunnable
+class ChildDispatcher
 {
 public:
-    PipeRunnable() :
+    ChildDispatcher() :
+        _wsdPipeReader("wsd_pipe_rd", readerBroker),
         _childPipeReader("child_pipe_rd", readerChild)
     {
     }
 
+    /// 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; });
+    }
+
+    /// Used for benchmarking child initialization.
+    bool waitForResponse()
+    {
+        std::string response;
+        if (_childPipeReader.readLine(response, [](){ return TerminationFlag; }) <= 0)
+            Log::error("Error reading response to benchmark message from child");
+        else
+            Log::debug("got response '" + response + "'");
+        return response == "started";
+    }
+
+private:
+
     bool createSession(const std::shared_ptr<ChildProcess>& child, const std::string& session, const std::string& url)
     {
         const std::string message = "session " + session + " " + url + "\n";
@@ -256,17 +277,8 @@ public:
         }
     }
 
-    bool waitForResponse()
-    {
-        std::string response;
-        if (_childPipeReader.readLine(response, [](){ return TerminationFlag; }) <= 0)
-            Log::error("Error reading response to benchmark message from child");
-        else
-            Log::debug("got response '" + response + "'");
-        return response == "started";
-    }
-
 private:
+    IoUtil::PipeReader _wsdPipeReader;
     IoUtil::PipeReader _childPipeReader;
 };
 
@@ -648,18 +660,16 @@ int main(int argc, char** argv)
         dropCapability(CAP_FOWNER);
     }
 
-    PipeRunnable pipeHandler;
+    ChildDispatcher childDispatcher;
     Log::info("loolbroker is ready.");
 
     Poco::Timestamp startTime;
-    IoUtil::PipeReader pipeReader(FIFO_LOOLWSD, readerBroker);
 
     while (!TerminationFlag)
     {
-        if (!pipeReader.processOnce([&pipeHandler](std::string& message) { pipeHandler.handleInput(message); return true; },
-                                    []() { return TerminationFlag; }))
+        if (!childDispatcher.pollAndDispatch())
         {
-            Log::info("Reading pipe [" + pipeReader.getName() + "] flagged for termination.");
+            Log::info("Child dispatcher flagged for termination.");
             break;
         }
 
@@ -783,7 +793,7 @@ int main(int argc, char** argv)
         int numSpawned = 0;
         while (numSpawned < numPreSpawnedChildren)
         {
-            if (pipeHandler.waitForResponse())
+            if (childDispatcher.waitForResponse())
                 numSpawned++;
             Log::info("got children " + std::to_string(numSpawned));
         }


More information about the Libreoffice-commits mailing list