[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loleaflet/src loolwsd/LOOLWSD.cpp

Jan Holesovsky kendy at collabora.com
Mon Mar 14 17:36:37 UTC 2016


 loleaflet/src/core/Socket.js |    3 +++
 loolwsd/LOOLWSD.cpp          |   16 +++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

New commits:
commit 9fc5ffc59244f6ca4f1d876e95ef9823b1cbab48
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 connection.
    
    This is to distinguish the deliberate close of connection, and timeout,
    connection drop, or forced close.

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 2420d91..110b98e 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -20,6 +20,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/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7387d27..ff3ddbc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -382,6 +382,7 @@ public:
         Thread queueHandlerThread;
         QueueHandler handler(queue);
         Poco::Timespan waitTime(LOOLWSD::POLL_TIMEOUT);
+        bool normalShutdown = false;
 
         try
         {
@@ -436,6 +437,9 @@ public:
                             std::string firstLine = getFirstLine(buffer, n);
                             StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
+                            if (tokens.count() == 1 && tokens[0] == "closeconnection")
+                                normalShutdown = true;
+
                             if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != WebSocket::FrameFlags::FRAME_FLAG_FIN)
                             {
                                 // One WS message split into multiple frames.
@@ -484,9 +488,19 @@ public:
                 while (!LOOLWSD::isShutDown &&
                         (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
 
+                if (normalShutdown)
+                {
+                    Application::instance().logger().information(Util::logPrefix() + "Deliberate shutdown, clearing the queue.");
+                    queue.clear();
+                }
+                else
+                {
+                    Application::instance().logger().information(Util::logPrefix() + "Non-deliberate shutdown, saving the document before tearing down.");
+                    queue.put("uno .uno:Save");
+                }
+
                 Application::instance().logger().information(Util::logPrefix() + "Finished the websocket handling.");
 
-                queue.clear();
                 queue.put("eof");
                 queueHandlerThread.join();
 


More information about the Libreoffice-commits mailing list