[Libreoffice-commits] online.git: Branch 'private/hcvcastro/forking' - loolwsd/MasterProcessSession.cpp

Henry Castro hcastro at collabora.com
Sun Sep 27 15:49:28 PDT 2015


 loolwsd/MasterProcessSession.cpp |   41 +++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

New commits:
commit 334874cc527f8726992b0b9361a15104b61ca9c0
Author: Henry Castro <hcastro at collabora.com>
Date:   Sun Sep 27 18:48:28 2015 -0400

    loolwsd: drop client connection after waiting child connection.

diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 568a7d1..566f4ab 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -397,25 +397,50 @@ void MasterProcessSession::sendTile(const char *buffer, int length, StringTokeni
 
 void MasterProcessSession::dispatchChild()
 {
+    short nRequest = 3;
+    bool  bFound = false;
+
     // Copy document into jail using the fixed name
 
     std::shared_ptr<MasterProcessSession> childSession;
     std::unique_lock<std::mutex> lock(_availableChildSessionMutex);
 
-    std::cout << Util::logPrefix() << "_availableChildSessions size=" << _availableChildSessions.size() << std::endl;
-
-    if (_availableChildSessions.size() == 0)
+    std::cout << Util::logPrefix() << "waiting for a child session permission for " << Thread::currentTid() << std::endl;
+    while (nRequest-- && !bFound)
     {
-        std::cout << Util::logPrefix() << "waiting for a child session to become available" << std::endl;
-        _availableChildSessionCV.wait(lock, [] { return _availableChildSessions.size() > 0; });
-        std::cout << Util::logPrefix() << "waiting done" << std::endl;
+        _availableChildSessionCV.wait_for(
+            lock,
+            std::chrono::milliseconds(2000),
+            [&bFound]
+            {
+                return (bFound = _availableChildSessions.find(Thread::currentTid()) != _availableChildSessions.end());
+            });
+
+        if (!bFound)
+        {
+            std::cout << Util::logPrefix() << "trying ..." << nRequest << std::endl;
+            // request again new URL session
+            std::string aMessage = "request " + std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
+            Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
+        }
     }
 
-    childSession = _availableChildSessions[Thread::currentTid()];
-    _availableChildSessions.erase(Thread::currentTid());
+    if ( bFound )
+    {
+        std::cout << Util::logPrefix() << "waiting child session permission, done!" << std::endl;
+        childSession = _availableChildSessions[Thread::currentTid()];
+        _availableChildSessions.erase(Thread::currentTid());
+    }
 
     lock.unlock();
 
+    if ( !nRequest && !bFound )
+    {
+        // it cannot get connected.  shutdown.
+        Util::shutdownWebSocket(*_ws);
+        return;
+    }
+
     // Assume a valid URI
     URI aUri(_docURL);
 


More information about the Libreoffice-commits mailing list