[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Jan 3 07:23:21 PST 2016


 loolwsd/ChildProcessSession.cpp  |    2 -
 loolwsd/LOOLKit.cpp              |   43 ++++++++++++++++++++++++++-------------
 loolwsd/LOOLWSD.cpp              |    5 +++-
 loolwsd/MasterProcessSession.cpp |    2 -
 4 files changed, 35 insertions(+), 17 deletions(-)

New commits:
commit eeb91f63355e77feb31bcdac67280ef9a45fc578
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Wed Dec 30 12:10:31 2015 -0500

    loolwsd: send eof to disconnect
    
    Change-Id: I02ec901fd75671a3f4bf6be54f08dfdf6d157837
    Reviewed-on: https://gerrit.libreoffice.org/21063
    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 e8d4b49..f74e353 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -67,7 +67,7 @@ ChildProcessSession::~ChildProcessSession()
     }
 
     if (LIBREOFFICEKIT_HAS(_loKit, registerCallback))
-        _loKit->pClass->registerCallback(_loKit, 0, 0);
+        _loKit->pClass->registerCallback(_loKit, nullptr, this);
 }
 
 bool ChildProcessSession::_handleInput(const char *buffer, int length)
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index a5795a9..8205a4f 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -374,9 +374,23 @@ public:
         _loKit(loKit),
         _loKitDocument(loKitDocument),
         _childId(childId),
-        _sessionId(sessionId)
+        _sessionId(sessionId),
+        _stop(false)
     {
-        Log::info("New connection in child: " + childId + ", thread: " + _sessionId);
+        Log::info("Connection ctor in child: " + childId + ", thread: " + _sessionId);
+    }
+
+    ~Connection()
+    {
+        Log::info("~Connection dtor in child: " + _childId + ", thread: " + _sessionId);
+        stop();
+    }
+
+    const std::string& getSessionId() const { return _sessionId; }
+
+    LibreOfficeKitDocument * getLOKitDocument()
+    {
+        return (_session ? _session->_loKitDocument : nullptr);
     }
 
     void start()
@@ -389,15 +403,15 @@ public:
         return _thread.isRunning();
     }
 
-    void join()
+    void stop()
     {
-        _thread.join();
+        _stop = true;
     }
 
-    LibreOfficeKitDocument * getLOKitDocument()
+    void join()
     {
-        return (_session ? _session->_loKitDocument : nullptr);
-    };
+        _thread.join();
+    }
 
     void run() override
     {
@@ -443,6 +457,9 @@ public:
                 if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
                 {
                     std::string firstLine = getFirstLine(buffer, n);
+                    if (firstLine == "eof")
+                        break;
+
                     StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
                     // The only kind of messages a child process receives are the single-line ones (?)
@@ -451,11 +468,13 @@ public:
                     queue.put(firstLine);
                 }
             }
-            while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
+            while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !_stop);
 
             queue.clear();
             queue.put("eof");
             queueHandlerThread.join();
+
+            _session->sendTextFrame("eof");
         }
         catch (const Exception& exc)
         {
@@ -471,18 +490,14 @@ public:
         Log::debug("Thread [" + thread_name + "] finished.");
     }
 
-    ~Connection()
-    {
-        Log::info("Closing connection in child: " + _childId + ", thread: " + _sessionId);
-    }
-
 private:
     LibreOfficeKit *_loKit;
     LibreOfficeKitDocument *_loKitDocument;
     const std::string _childId;
-    std::string _sessionId;
+    const std::string _sessionId;
     Thread _thread;
     std::shared_ptr<ChildProcessSession> _session;
+    volatile bool _stop;
 };
 
 // A document container.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 47cb3ed..f21bfd4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -176,7 +176,7 @@ public:
 
         while (true)
         {
-            std::string input = _queue.get();
+            const std::string input = _queue.get();
             if (input == "eof")
                 break;
             if (!_session->handleInput(input.c_str(), input.size()))
@@ -415,6 +415,9 @@ public:
                         else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
                         {
                             const std::string firstLine = getFirstLine(buffer, n);
+                            if (firstLine == "eof")
+                                break;
+
                             StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
                             if (kind == LOOLSession::Kind::ToClient &&
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index e56ed1c..2d5478d 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -67,7 +67,7 @@ MasterProcessSession::~MasterProcessSession()
     auto peer = _peer.lock();
     if (_kind == Kind::ToClient && peer)
     {
-        Util::shutdownWebSocket(*(peer->_ws));
+        peer->sendTextFrame("eof");
     }
     else
     if (_kind == Kind::ToPrisoner && peer)


More information about the Libreoffice-commits mailing list