[Libreoffice-commits] online.git: loolwsd/IoUtil.cpp loolwsd/IoUtil.hpp loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/TileCache.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Mar 30 01:46:52 UTC 2016


 loolwsd/IoUtil.cpp     |    4 ++--
 loolwsd/IoUtil.hpp     |    3 ++-
 loolwsd/LOOLBroker.cpp |   20 ++++++++++++--------
 loolwsd/LOOLKit.cpp    |   19 ++++++++++---------
 loolwsd/TileCache.cpp  |    1 -
 5 files changed, 26 insertions(+), 21 deletions(-)

New commits:
commit 3d2c2fde3b5c9b0e6db19e3d6012b47c1a4be0fa
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Mar 27 19:43:15 2016 -0400

    loolwsd: logging and misc cleanup
    
    Change-Id: If3cea8191fe15fc752c436cd33d2a68dc2d88598
    Reviewed-on: https://gerrit.libreoffice.org/23638
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index cf46e7e..70e386c 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -247,7 +247,7 @@ ssize_t readFIFO(int pipe, char* buffer, ssize_t size)
     return bytes;
 }
 
-ssize_t readMessage(int pipe, char* buffer, ssize_t size)
+ssize_t readMessage(const int pipe, char* buffer, const ssize_t size, const size_t timeoutSec)
 {
     struct pollfd pollPipe;
 
@@ -255,7 +255,7 @@ ssize_t readMessage(int pipe, char* buffer, ssize_t size)
     pollPipe.events = POLLIN;
     pollPipe.revents = 0;
 
-    const int nPoll = poll(&pollPipe, 1, CHILD_TIMEOUT_SECS * 1000);
+    const int nPoll = poll(&pollPipe, 1, timeoutSec * 1000);
     if ( nPoll < 0 )
         return -1;
 
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index 1647e29..8a0f53d 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -42,7 +42,8 @@ namespace IoUtil
 
     ssize_t readFIFO(int pipe, char* buffer, ssize_t size);
 
-    ssize_t readMessage(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);
 
     void pollPipeForReading(pollfd& pollPipe, const std::string& targetPipeName , const int& targetPipe,
                             std::function<void(std::string& message)> handler);
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 59bb30c..b62b26b 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -196,19 +196,19 @@ public:
     {
     }
 
-    ssize_t getResponseLine(int pipeReader, std::string& response)
+    ssize_t getResponseLine(const int pipeReader, std::string& response)
     {
         ssize_t bytes = -1;
         response.clear();
 
         try
         {
-            while (true)
+            for (;;)
             {
                 if (_start == _end)
                 {
                     bytes = IoUtil::readMessage(pipeReader, _buffer, sizeof(_buffer));
-                    if ( bytes < 0 )
+                    if (bytes < 0)
                     {
                         _start = _end = nullptr;
                         break;
@@ -218,7 +218,7 @@ public:
                     _end = _buffer + bytes;
                 }
 
-                if ( _start != _end )
+                if (_start != _end)
                 {
                     char byteChar = *_start++;
                     while (_start != _end && byteChar != '\r' && byteChar != '\n')
@@ -229,7 +229,7 @@ public:
 
                     if (byteChar == '\r' && *_start == '\n')
                     {
-                        _start++;
+                        ++_start;
                         break;
                     }
                 }
@@ -341,9 +341,13 @@ public:
                 const auto childPid = std::to_string(child->getPid());
                 const auto isEmptyChild = child->getUrl().empty();
                 if (isEmptyChild)
-                    Log::debug("Found URL [" + url + "] hosted on child [" + childPid + "].");
-                else
+                {
                     Log::debug("URL [" + url + "] is not hosted. Using empty child [" + childPid + "].");
+                }
+                else
+                {
+                    Log::debug("Found URL [" + url + "] hosted on child [" + childPid + "].");
+                }
 
                 if (createThread(child->getPid(), session, url))
                 {
@@ -710,7 +714,7 @@ int main(int argc, char** argv)
     const std::string pipeNotify = Path(pipePath, FIFO_NOTIFY).toString();
     if ((writerNotify = open(pipeNotify.c_str(), O_WRONLY) ) < 0)
     {
-        Log::error("Error: pipe opened for writing.");
+        Log::error("Error: failed to open notify pipe [" + FIFO_NOTIFY + "] for writing.");
         exit(Application::EXIT_SOFTWARE);
     }
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index a79f1db..9d9dbc5 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -353,7 +353,7 @@ public:
                 if (aIterator.second->isRunning())
                 {
                     std::shared_ptr<WebSocket> ws = aIterator.second->getWebSocket();
-                    if ( ws )
+                    if (ws)
                     {
                         ws->shutdownReceive();
                         aIterator.second->join();
@@ -379,6 +379,8 @@ public:
         }
     }
 
+    const std::string& getUrl() const { return _url; }
+
     void createSession(const std::string& sessionId, const unsigned intSessionId)
     {
         std::unique_lock<std::mutex> lock(_mutex);
@@ -753,7 +755,7 @@ private:
 private:
 
     const bool _multiView;
-    LibreOfficeKit *_loKit;
+    LibreOfficeKit* const _loKit;
     const std::string _jailId;
     const std::string _docKey;
     const std::string _url;
@@ -826,10 +828,8 @@ void lokit_main(const std::string& childRoot,
 
     try
     {
-        int writerBroker;
-        int readerBroker;
-
-        if ((readerBroker = open(pipe.c_str(), O_RDONLY) ) < 0)
+        const int readerBroker = open(pipe.c_str(), O_RDONLY);
+        if (readerBroker < 0)
         {
             Log::error("Error: failed to open pipe [" + pipe + "] read only.");
             std::exit(Application::EXIT_SOFTWARE);
@@ -837,9 +837,10 @@ void lokit_main(const std::string& childRoot,
 
         const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH);
         const std::string pipeBroker = Path(pipePath, FIFO_BROKER).toString();
-        if ((writerBroker = open(pipeBroker.c_str(), O_WRONLY) ) < 0)
+        const int writerBroker = open(pipeBroker.c_str(), O_WRONLY);
+        if (writerBroker < 0)
         {
-            Log::error("Error: failed to open pipe [" + FIFO_BROKER + "] write only.");
+            Log::error("Error: failed to open Broker write pipe [" + FIFO_BROKER + "].");
             std::exit(Application::EXIT_SOFTWARE);
         }
 
@@ -847,7 +848,7 @@ void lokit_main(const std::string& childRoot,
         const std::string pipeNotify = Path(pipePath, FIFO_NOTIFY).toString();
         if ((writerNotify = open(pipeNotify.c_str(), O_WRONLY) ) < 0)
         {
-            Log::error("Error: pipe opened for writing.");
+            Log::error("Error: failed to open notify pipe [" + FIFO_NOTIFY + "] for writing.");
             exit(Application::EXIT_SOFTWARE);
         }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index bed7681..b59e720 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -28,7 +28,6 @@
 #include <Poco/URI.h>
 
 #include "Storage.hpp"
-#include "LOOLWSD.hpp"
 #include "LOOLProtocol.hpp"
 #include "TileCache.hpp"
 #include "Util.hpp"


More information about the Libreoffice-commits mailing list