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

Tor Lillqvist tml at collabora.com
Thu Apr 7 17:23:29 UTC 2016


 loolwsd/Admin.cpp               |    7 +----
 loolwsd/ChildProcessSession.cpp |    4 ---
 loolwsd/Common.hpp              |    1 
 loolwsd/IoUtil.cpp              |   50 ++++++++--------------------------------
 loolwsd/IoUtil.hpp              |    7 -----
 loolwsd/LOOLKit.cpp             |   14 ++++-------
 loolwsd/LOOLWSD.cpp             |   23 +++++-------------
 7 files changed, 27 insertions(+), 79 deletions(-)

New commits:
commit c71d12ae63b43636f9424632a9132305036c1d26
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 20:22:32 2016 +0300

    Process name and id are already part of each logging output line

diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 5dee1a9..50637ec 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1005,7 +1005,7 @@ void lokit_main(const std::string& childRoot,
             std::exit(Application::EXIT_SOFTWARE);
         }
 
-        Log::info("loolkit [" + std::to_string(Process::id()) + "] is ready.");
+        Log::info("Process is ready.");
 
         // Open websocket connection between the child process and WSD.
         HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
commit 557ca90be14b495a27007883038f951426ee6b3e
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 20:18:22 2016 +0300

    Remove unused IoUtil::readMessage()

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 871f0dd..35a8e24 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -244,27 +244,6 @@ ssize_t readFIFO(int pipe, char* buffer, ssize_t size)
     return bytes;
 }
 
-ssize_t readMessage(const int pipe, char* buffer, const ssize_t size, const size_t timeoutSec)
-{
-    struct pollfd pollPipe;
-
-    pollPipe.fd = pipe;
-    pollPipe.events = POLLIN;
-    pollPipe.revents = 0;
-
-    const int nPoll = poll(&pollPipe, 1, timeoutSec * 1000);
-    if ( nPoll < 0 )
-        return -1;
-
-    if ( nPoll == 0 )
-        errno = ETIME;
-
-    if( (pollPipe.revents & POLLIN) != 0 )
-        return readFIFO(pipe, buffer, size);
-
-    return -1;
-}
-
 /// Reads a single line from a pipe.
 /// Returns 0 for timeout, <0 for error, and >0 on success.
 /// On success, line will contain the read message.
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index c01e814..4ad06f5 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -40,9 +40,6 @@ namespace IoUtil
 
     ssize_t readFIFO(int pipe, char* buffer, ssize_t size);
 
-    ssize_t readMessage(const int pipe, char* buffer, const ssize_t size,
-                        const size_t timeoutSec = CHILD_TIMEOUT_SECS);
-
     class PipeReader
     {
     public:
commit 16034f66853947b309a610c49779466e68b56f50
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 20:09:35 2016 +0300

    Bin unused INTERVAL_PROBES

diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index 89e780b..1423251 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -18,7 +18,6 @@ constexpr int MAX_SESSIONS = 1024;
 
 constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 constexpr int MASTER_PORT_NUMBER = 9981;
-constexpr int INTERVAL_PROBES = 10;
 constexpr int MAINTENANCE_INTERVAL = 1;
 constexpr int CHILD_TIMEOUT_SECS = 10;
 constexpr int POLL_TIMEOUT_MS = 1000;
commit 4ed3393f164fd55f6c4ff9a227cbb5972600966d
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 20:03:26 2016 +0300

    Nothing ever passed for the pollTimeoutMs parameter so use the default value in-line

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 632d2bc..871f0dd 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -40,13 +40,12 @@ namespace IoUtil
 void SocketProcessor(std::shared_ptr<WebSocket> ws,
                      Poco::Net::HTTPResponse& response,
                      std::function<bool(const std::vector<char>&)> handler,
-                     std::function<bool()> stopPredicate,
-                     const size_t pollTimeoutMs)
+                     std::function<bool()> stopPredicate)
 {
     Log::info("SocketProcessor starting.");
 
     // Timeout given is in microseconds.
-    const Poco::Timespan waitTime(pollTimeoutMs * 1000);
+    const Poco::Timespan waitTime(POLL_TIMEOUT_MS * 1000);
     try
     {
         ws->setReceiveTimeout(0);
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index 42b1f8c..c01e814 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -26,8 +26,7 @@ namespace IoUtil
     void SocketProcessor(std::shared_ptr<Poco::Net::WebSocket> ws,
                          Poco::Net::HTTPResponse& response,
                          std::function<bool(const std::vector<char>&)> handler,
-                         std::function<bool()> stopPredicate,
-                         const size_t pollTimeoutMs = POLL_TIMEOUT_MS);
+                         std::function<bool()> stopPredicate);
 
     /// Call WebSocket::shutdown() ignoring Poco::IOException.
     void shutdownWebSocket(std::shared_ptr<Poco::Net::WebSocket> ws);
commit 584a8057813f1354238ae2d4f998be9a9004ec8e
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 20:00:57 2016 +0300

    The SocketProcessor() 'name' parameter can now be dropped

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 081d410..632d2bc 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -41,14 +41,8 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
                      Poco::Net::HTTPResponse& response,
                      std::function<bool(const std::vector<char>&)> handler,
                      std::function<bool()> stopPredicate,
-                     std::string name,
                      const size_t pollTimeoutMs)
 {
-    if (!name.empty())
-    {
-        name = "[" + name + "] ";
-    }
-
     Log::info("SocketProcessor starting.");
 
     // Timeout given is in microseconds.
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index 17dfcc8..42b1f8c 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -27,7 +27,6 @@ namespace IoUtil
                          Poco::Net::HTTPResponse& response,
                          std::function<bool(const std::vector<char>&)> handler,
                          std::function<bool()> stopPredicate,
-                         std::string name = std::string(),
                          const size_t pollTimeoutMs = POLL_TIMEOUT_MS);
 
     /// Call WebSocket::shutdown() ignoring Poco::IOException.
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index da3423c..5dee1a9 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1059,8 +1059,7 @@ void lokit_main(const std::string& childRoot,
 
                     return true;
                 },
-                [](){ return TerminationFlag; },
-                socketName);
+                [](){ return TerminationFlag; });
 
         // Cleanup jail.
         Util::removeFile(jailPath, true);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index fad0b1b..d8669d4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -512,9 +512,7 @@ private:
 
                 return true;
             },
-            []() { return TerminationFlag; },
-            "Client_ws_" + id
-            );
+            []() { return TerminationFlag; });
 
         if (docBroker->getSessionsCount() == 1 && !normalShutdown && !session->_bLoadError)
         {
@@ -758,9 +756,7 @@ public:
                 {
                     return session->handleInput(payload.data(), payload.size());
                 },
-                []() { return TerminationFlag; },
-                "Child_ws_" + sessionId
-                );
+                []() { return TerminationFlag; });
         }
         catch (const Exception& exc)
         {
commit 5ea6c4bacf2b6f0d59cef41b1b8a3a4e962041be
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 19:52:53 2016 +0300

    No need to show the SocketProcessor 'name' in the log
    
    The thread name already identifies it sufficiently as can be seen:
    
    kit-05108-00 00:00:01.662974 [loolkit        ] [ChildControllerWS] Starting Socket Processor.
    wsd-05087-03 00:00:08.126842 [client_ws_0002 ] [Client_ws_0002] Starting Socket Processor.
    wsd-05087-05 00:00:08.153688 [prison_ws_0002 ] [Child_ws_0002] Starting Socket Processor.

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 7de0230..081d410 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -49,7 +49,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
         name = "[" + name + "] ";
     }
 
-    Log::info(name + "Starting Socket Processor.");
+    Log::info("SocketProcessor starting.");
 
     // Timeout given is in microseconds.
     const Poco::Timespan waitTime(pollTimeoutMs * 1000);
@@ -67,7 +67,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
             stop = stopPredicate();
             if (stop)
             {
-                Log::info(name + "Termination flagged. Finishing.");
+                Log::info("Termination flagged. Finishing.");
                 break;
             }
 
@@ -101,7 +101,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
             }
             else if (n <= 0 || ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE))
             {
-                Log::warn(name + "Connection closed.");
+                Log::warn("Connection closed.");
                 break;
             }
 
@@ -145,30 +145,30 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
 
             if (n <= 0 || (flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_CLOSE)
             {
-                Log::warn(name + "Connection closed.");
+                Log::warn("Connection closed.");
                 break;
             }
 
             if (firstLine == "eof")
             {
-                Log::info(name + "Received EOF. Finishing.");
+                Log::info("Received EOF. Finishing.");
                 break;
             }
 
             // Call the handler.
             if (!handler(payload))
             {
-                Log::info(name + "Socket handler flagged to finish.");
+                Log::info("Socket handler flagged to finish.");
                 break;
             }
         }
 
-        Log::debug() << name << "Finishing SocketProcessor. TerminationFlag: " << stop
+        Log::debug() << "SocketProcessor finishing. TerminationFlag: " << stop
                      << ", payload size: " << payload.size()
                      << ", flags: " << std::hex << flags << Log::end;
         if (payload.size() > 1)
         {
-            Log::warn(name + "Last message will not be processed: [" +
+            Log::warn("Last message will not be processed: [" +
                       LOOLProtocol::getFirstLine(payload.data(), payload.size()) + "].");
         }
     }
@@ -193,7 +193,7 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
         Log::error("SocketProcessor: NetException: " + exc.message());
     }
 
-    Log::info(name + "Finished Socket Processor.");
+    Log::info("SocketProcessor finished.");
 }
 
 void shutdownWebSocket(std::shared_ptr<Poco::Net::WebSocket> ws)
commit d36c8bbbba26ff9241282c27e3331e0101f03cd7
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 19:31:56 2016 +0300

    Avoid some use-once variables
    
    Also, use different names for the HTTPRequestHandler threads in
    ClientRequestHandlerFactory and PrisonerRequestHandlerFactory.

diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp
index 3bb963e..9c8e9aa 100644
--- a/loolwsd/Admin.cpp
+++ b/loolwsd/Admin.cpp
@@ -333,9 +333,8 @@ void AdminRequestHandler::handleRequest(HTTPServerRequest& request, HTTPServerRe
 {
     // Different session id pool for admin sessions (?)
     const auto nSessionId = Util::decodeId(LOOLWSD::GenSessionId());
-    const std::string thread_name = "admin_ws_" + std::to_string(nSessionId);
 
-    Util::setThreadName(thread_name);
+    Util::setThreadName("admin_ws_" + std::to_string(nSessionId));
 
     Log::debug("Thread started.");
 
@@ -449,9 +448,7 @@ void Admin::run()
     _cpuStatsTask = new CpuStats(this);
     _cpuStatsTimer.schedule(_cpuStatsTask, _cpuStatsTaskInterval, _cpuStatsTaskInterval);
 
-    static const std::string thread_name = "admin_thread";
-
-    Util::setThreadName(thread_name);
+    Util::setThreadName("admin_thread");
 
     Log::debug("Thread started.");
 
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 2e4ecd4..8750e18 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -198,9 +198,7 @@ public:
 
     void run()
     {
-        static const std::string thread_name = "kit_callback";
-
-        Util::setThreadName(thread_name);
+        Util::setThreadName("kit_callback");
 
         Log::debug("Thread started.");
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 9b83d1b..da3423c 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -277,9 +277,7 @@ public:
 
     void run() override
     {
-        const std::string thread_name = "kit_ws_" + _session->getId();
-
-        Util::setThreadName(thread_name);
+        Util::setThreadName("kit_ws_" + _session->getId());
 
         Log::debug("Thread started.");
 
@@ -894,9 +892,8 @@ void lokit_main(const std::string& childRoot,
     // the jailId (i.e. the path) implicitly by knowing our pid.
     static const std::string pid = std::to_string(Process::id());
     static const std::string jailId = pid;
-    static const std::string process_name = "loolkit";
 
-    Util::setThreadName(process_name);
+    Util::setThreadName("loolkit");
 
     Log::debug("Process started.");
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 055a164..fad0b1b 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -583,9 +583,8 @@ public:
     void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override
     {
         const auto id = LOOLWSD::GenSessionId();
-        const std::string thread_name = "client_ws_" + id;
 
-        Util::setThreadName(thread_name);
+        Util::setThreadName("client_ws_" + id);
 
         Log::debug("Thread started.");
 
@@ -632,9 +631,7 @@ public:
 
     void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override
     {
-        std::string thread_name = "prison_ws_";
-
-        Util::setThreadName(thread_name);
+        Util::setThreadName("prison_ws");
 
         Log::debug("Child connection with URI [" + request.getURI() + "].");
 
@@ -695,9 +692,7 @@ public:
                 }
             }
 
-            thread_name += sessionId;
-
-            Util::setThreadName(thread_name);
+            Util::setThreadName("prison_ws_" + sessionId);
 
             // Misleading debug message, we obviously started already a while ago and have done lots
             // of stuff already.
@@ -805,7 +800,7 @@ public:
 
     HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override
     {
-        Util::setThreadName("request_handler");
+        Util::setThreadName("client_req_hdl");
 
         auto logger = Log::info();
         logger << "Request from " << request.clientAddress().toString() << ": "
@@ -854,7 +849,7 @@ class PrisonerRequestHandlerFactory: public HTTPRequestHandlerFactory
 public:
     HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override
     {
-        Util::setThreadName("request_handler");
+        Util::setThreadName("prsnr_req_hdl");
 
         auto logger = Log::info();
         logger << "Request from " << request.clientAddress().toString() << ": "
commit 9acc0b052ebdb6ed3abef0fb61cb967966cc047d
Author: Tor Lillqvist <tml at collabora.com>
Date:   Thu Apr 7 19:26:01 2016 +0300

    Bin one more redundant thread name in debug log

diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 5a0f453..9b83d1b 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -332,7 +332,7 @@ public:
                 }
             }
             while (!_stop && n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
-            Log::debug() << "Finishing " << thread_name << ". stop " << _stop
+            Log::debug() << "Finishing. stop " << _stop
                          << ", payload size: " << n
                          << ", flags: " << std::hex << flags << Log::end;
 


More information about the Libreoffice-commits mailing list