[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/Common.hpp loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Dec 27 20:12:32 PST 2015


 loolwsd/ChildProcessSession.cpp |    6 +++---
 loolwsd/Common.hpp              |    3 +++
 loolwsd/LOOLBroker.cpp          |    9 ++++++++-
 loolwsd/LOOLKit.cpp             |    6 ++++++
 loolwsd/LOOLWSD.cpp             |    8 ++++----
 loolwsd/LOOLWSD.hpp             |    1 -
 6 files changed, 24 insertions(+), 9 deletions(-)

New commits:
commit b2d124af9380ea02de1837ebfee9bca4fc0f06cf
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Dec 27 17:46:42 2015 -0500

    loolwsd: proper handling of non-default client port number
    
    Change-Id: I388f0ce0252c5f7889e77c4d85b4cf21d4a222b6
    Reviewed-on: https://gerrit.libreoffice.org/20979
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index c31847f..7ef8a39 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -19,6 +19,7 @@
 #include <Poco/StringTokenizer.h>
 #include <Poco/URI.h>
 
+#include "Common.hpp"
 #include "ChildProcessSession.hpp"
 #include "LOKitHelper.hpp"
 #include "LOOLProtocol.hpp"
@@ -520,9 +521,8 @@ bool ChildProcessSession::downloadAs(const char* /*buffer*/, int /*length*/, Str
             format.size() == 0 ? nullptr :format.c_str(),
             filterOptions.size() == 0 ? nullptr : filterOptions.c_str());
 
-    //TODO: handle download portNumber.
-    //sendTextFrame("downloadas: jail=" + _childId + " dir=" + tmpDir + " name=" + name +
-    //        " port=" + std::to_string(LOOLWSD::portNumber) + " id=" + id);
+    sendTextFrame("downloadas: jail=" + _childId + " dir=" + tmpDir + " name=" + name +
+            " port=" + std::to_string(ClientPortNumber) + " id=" + id);
     return true;
 }
 
diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index e5c9406..fba45a4 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -17,5 +17,8 @@ static const int INTERVAL_PROBES = 10;
 static const int MAINTENANCE_INTERVAL = 1;
 static const int POLL_TIMEOUT = 1000000;
 
+// The client port number, which is changed via loolwsd args.
+static int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
+
 #endif
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index c82b564..a55aeaa 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -558,7 +558,6 @@ static int createLibreOfficeKit(bool sharePages, std::string loSubPath, Poco::UI
     }
     else
     {
-        Process::Args args;
         const std::string executable = "loolkit";
         const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
 
@@ -568,9 +567,11 @@ static int createLibreOfficeKit(bool sharePages, std::string loSubPath, Poco::UI
             return -1;
         }
 
+        Process::Args args;
         args.push_back("--losubpath=" + loSubPath);
         args.push_back("--child=" + std::to_string(childID));
         args.push_back("--pipe=" + pipe);
+        args.push_back("--clientport=" + ClientPortNumber);
 
         Log::info("Launching LibreOfficeKit: " + executable + " " +
                   Poco::cat(std::string(" "), args.begin(), args.end()));
@@ -665,6 +666,12 @@ int main(int argc, char** argv)
             if (*eq)
                 _numPreSpawnedChildren = std::stoi(std::string(++eq));
         }
+        else if (strstr(cmd, "--clientport=") == cmd)
+        {
+            eq = strchrnul(cmd, '=');
+            if (*eq)
+                ClientPortNumber = std::stoll(std::string(++eq));
+        }
     }
 
     if (loSubPath.empty())
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index c9e893f..332879a 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -701,6 +701,12 @@ int main(int argc, char** argv)
             if (*eq)
                 _pipe = std::string(++eq);
         }
+        else if (strstr(cmd, "--clientport=") == cmd)
+        {
+            eq = strchrnul(cmd, '=');
+            if (*eq)
+                ClientPortNumber = std::stoll(std::string(++eq));
+        }
     }
 
     if (loSubPath.empty())
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f736d47..683e304 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -660,7 +660,6 @@ private:
     HTTPServer& _srv;
 };
 
-int LOOLWSD::portNumber = DEFAULT_CLIENT_PORT_NUMBER;
 int LOOLWSD::timeoutCounter = 0;
 int LOOLWSD::writerBroker = -1;
 Poco::UInt64 LOOLWSD::_childId = 0;
@@ -800,7 +799,7 @@ void LOOLWSD::handleOption(const std::string& optionName, const std::string& val
         exit(Application::EXIT_OK);
     }
     else if (optionName == "port")
-        portNumber = std::stoi(value);
+        ClientPortNumber = std::stoi(value);
     else if (optionName == "cache")
         cache = value;
     else if (optionName == "systemplate")
@@ -843,6 +842,7 @@ int LOOLWSD::createBroker()
     args.push_back("--lotemplate=" + loTemplate);
     args.push_back("--childroot=" + childRoot);
     args.push_back("--numprespawns=" + std::to_string(_numPreSpawnedChildren));
+    args.push_back("--clientport=" + std::to_string(ClientPortNumber));
 
     std::string executable = Path(Application::instance().commandPath()).parent().toString() + "loolbroker";
 
@@ -903,7 +903,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
         throw IncompatibleOptionsException("child");
     if (jail != "")
         throw IncompatibleOptionsException("jail");
-    if (portNumber == MASTER_PORT_NUMBER)
+    if (ClientPortNumber == MASTER_PORT_NUMBER)
         throw IncompatibleOptionsException("port");
 
     if (LOOLWSD::doTest)
@@ -935,7 +935,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 #endif
 
     // Start a server listening on the port for clients
-    ServerSocket svs(portNumber, _numPreSpawnedChildren*10);
+    ServerSocket svs(ClientPortNumber, _numPreSpawnedChildren*10);
     ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
     HTTPServer srv(new RequestHandlerFactory(), threadPool, svs, new HTTPServerParams);
 
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index a4b9058..907fd85 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -30,7 +30,6 @@ public:
 
     // An Application is a singleton anyway, so just keep these as
     // statics
-    static int portNumber;
     static int timeoutCounter;
     static int _numPreSpawnedChildren;
     static int writerBroker;


More information about the Libreoffice-commits mailing list