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

Henry Castro hcastro at collabora.com
Thu Jan 7 10:55:12 PST 2016


 loolwsd/LOOLBroker.cpp |   25 +++++++++++++++++++++++--
 loolwsd/LOOLKit.cpp    |   25 ++++++++++++++++---------
 2 files changed, 39 insertions(+), 11 deletions(-)

New commits:
commit b213464b3d03c19091b0dd2d318293088a593a6c
Author: Henry Castro <hcastro at collabora.com>
Date:   Thu Jan 7 14:55:11 2016 -0400

    loolwsd: ensure unique URL per lokit process

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 2ebbda8..dd90a47 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -203,6 +203,22 @@ public:
         return nBytes;
     }
 
+    bool isOKResponse(int nPID)
+    {
+        std::string aResponse;
+
+        if (getResponseLine(readerChild, aResponse) < 0)
+        {
+            //TODO: Cleanup broken children.
+            Log::error("Error reading child response: " + std::to_string(nPID) + ". Clearing cache.");
+            _cacheURL.clear();
+            return false;
+        }
+
+        StringTokenizer tokens(aResponse, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+        return (tokens[1] == "ok" ? true : false);
+    }
+
     ssize_t sendMessage(int nPipeWriter, const std::string& aMessage)
     {
         ssize_t nBytes = -1;
@@ -216,7 +232,6 @@ public:
 
     ssize_t createThread(Process::PID nPID, const std::string& aTID, const std::string& aURL)
     {
-        std::string aResponse;
         std::string aMessage = "thread " + aTID + " " + aURL + "\r\n";
         return sendMessage(_childProcesses[nPID], aMessage);
     }
@@ -289,6 +304,9 @@ public:
                 if (createThread(aIterURL->second, aTID, aURL) < 0)
                     Log::error("Cache: Error creating thread.");
 
+                if (!isOKResponse(aIterURL->second))
+                    Log::error("Cache Failed: Creating view for thread [" + aTID + "].");
+
                 return;
             }
             else
@@ -305,8 +323,10 @@ public:
                            aTID + "] on kit [" + std::to_string(nPID) + "].");
                 if (createThread(nPID, aTID, aURL) < 0)
                     Log::error("Search: Error creating thread.");
-                else
+                else if (isOKResponse(nPID))
                     _cacheURL[aURL] = nPID;
+                else
+                    Log::error("Failed: Creating view for thread [" + aTID + "].");
             }
             else
             {
@@ -799,6 +819,7 @@ int main(int argc, char** argv)
         {
             timeoutCounter = 0;
             sleep(MAINTENANCE_INTERVAL);
+            // TODO. lokit processes maintance
         }
     }
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index e309118..ba7ab62 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -699,10 +699,10 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s
                 {
                     pStart++;
                     StringTokenizer tokens(aMessage, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+                    aResponse = std::to_string(Process::id()) + " ";
 
                     if (tokens[0] == "search")
                     {
-                        aResponse = std::to_string(Process::id()) + " ";
                         if (_documents.empty())
                         {
                             aResponse += "empty \r\n";
@@ -712,26 +712,33 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s
                             const auto& it = _documents.find(tokens[1]);
                             aResponse += (it != _documents.end() ? "ok \r\n" : "no \r\n");
                         }
-
-                        Util::writeFIFO(writerBroker, aResponse.c_str(), aResponse.length());
                     }
                     else if (tokens[0] == "thread")
                     {
                         const std::string& sessionId = tokens[1];
                         const std::string& url = tokens[2];
-                        Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "].");
 
                         auto it = _documents.lower_bound(url);
-                        if (it == _documents.end())
-                            it = _documents.emplace_hint(it, url, std::make_shared<Document>(loKit.get(), jailId, url));
+                        if (it == _documents.end() || (it != _documents.end() && it->first == url))
+                        {
+                            Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "].");
+                            if (it == _documents.end())
+                                it = _documents.emplace_hint(it, url, std::make_shared<Document>(loKit.get(), jailId, url));
 
-                        it->second->createSession(sessionId);
+                            it->second->createSession(sessionId);
+                            aResponse += "ok \r\n";
+                        }
+                        else
+                        {
+                            aResponse += "no \r\n";
+                        }
                     }
                     else
                     {
-                        aResponse = "bad message \r\n";
-                        Util::writeFIFO(writerBroker, aResponse.c_str(), aResponse.length() );
+                        aResponse = "bad \r\n";
                     }
+
+                    Util::writeFIFO(writerBroker, aResponse.c_str(), aResponse.length() );
                     aMessage.clear();
                 }
             }


More information about the Libreoffice-commits mailing list