[Libreoffice-commits] online.git: loleaflet/src loolwsd/DocumentBroker.hpp loolwsd/LOOLWSD.cpp loolwsd/protocol.txt

Jan Holesovsky kendy at collabora.com
Tue Mar 15 08:49:49 UTC 2016


 loleaflet/src/core/Socket.js |    3 +++
 loolwsd/DocumentBroker.hpp   |    1 +
 loolwsd/LOOLWSD.cpp          |   20 +++++++++++++++++---
 loolwsd/protocol.txt         |    6 ++++++
 4 files changed, 27 insertions(+), 3 deletions(-)

New commits:
commit 2c1664b9d568a60881f999f2e6ae20f7336ace05
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Mon Mar 14 16:53:31 2016 +0100

    loolwsd, loleaflet: Let the server know when we are closing the session.
    
    This is to distinguish the deliberate close of connection, and timeout,
    connection drop, or forced close.
    
    When the last session is closed non-deliberately, force a save so that the
    edits are not lost.

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index b3e0e02..ce953f9 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -23,6 +23,9 @@ L.Socket = L.Class.extend({
 	},
 
 	close: function () {
+		// mark this as a deliberate shutdown
+		this.sendMessage('closeconnection');
+
 		this.socket.onerror = function () {};
 		this.socket.onclose = function () {};
 		this.socket.onmessage = function () {};
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index ad068d1..141fb2d 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -114,6 +114,7 @@ public:
     const std::string& getDocKey() const { return _docKey; }
     unsigned decSessions() { return --_sessionsCount; }
     unsigned incSessions() { return ++_sessionsCount; }
+    unsigned getSessionsCount() { return _sessionsCount; }
 
     std::string getJailRoot() const
     {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5435669..767f8b0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -565,8 +565,9 @@ private:
 
         Thread queueHandlerThread;
         queueHandlerThread.start(handler);
+        bool normalShutdown = false;
 
-        SocketProcessor(ws, response, [&session, &queue](const char* data, const int size, const bool singleLine)
+        SocketProcessor(ws, response, [&session, &queue, &normalShutdown](const char* data, const int size, const bool singleLine)
             {
                 // FIXME: There is a race here when a request A gets in the queue and
                 // is processed _after_ a later request B, because B gets processed
@@ -576,6 +577,9 @@ private:
                 const std::string firstLine = getFirstLine(data, size);
                 if (singleLine || firstLine.find("paste") == 0)
                 {
+                    if (firstLine == "closeconnection")
+                        normalShutdown = true;
+
                     queue.put(std::string(data, size));
                     return true;
                 }
@@ -585,8 +589,18 @@ private:
                 }
             });
 
-        Log::info("Finishing GET request handler for session [" + id + "]. Clearing and joining the queue.");
-        queue.clear();
+        if (docBroker->getSessionsCount() == 1 && !normalShutdown)
+        {
+            Log::info("Non-deliberate shutdown of the last session, saving the document before tearing down.");
+            queue.put("uno .uno:Save");
+        }
+        else
+        {
+            Log::info("Clearing the queue.");
+            queue.clear();
+        }
+
+        Log::info("Finishing GET request handler for session [" + id + "]. Joining the queue.");
         queue.put("eof");
         queueHandlerThread.join();
 
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index 334be17..3537a64 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -17,6 +17,12 @@ canceltiles
     dropped and will not be handled. There is no guarantee of exactly
     which tile: messages might still be sent back to the client.
 
+closeconnection
+
+    The socket is going to be shut down normally.  This is to distinguish
+    deliberate shutdown from the case when the connection was lost, or
+    the browser was killed etc.
+
 downloadas name=<fileName> id=<id> format=<document format> options=<SkipImages, etc>
 
     Exports the current document to the desired format and returns a download URL


More information about the Libreoffice-commits mailing list