[Libreoffice-commits] online.git: loolwsd/LOOLSession.cpp loolwsd/MasterProcessSession.cpp loolwsd/Util.cpp loolwsd/Util.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jan 21 08:07:01 PST 2016


 loolwsd/LOOLSession.cpp          |    5 +++--
 loolwsd/MasterProcessSession.cpp |    2 +-
 loolwsd/Util.cpp                 |    7 ++++---
 loolwsd/Util.hpp                 |    5 +++--
 4 files changed, 11 insertions(+), 8 deletions(-)

New commits:
commit d3fc5ac37ba0575f0dc628e51c3ec20de4bbfaec
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Jan 21 09:28:05 2016 -0500

    loolwsd: sockets are shutdown on disconnect
    
    Change-Id: I1c00be4648cff94013ceab87fcb607b9bb921535
    Reviewed-on: https://gerrit.libreoffice.org/21684
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 3522bd8..92d8f85 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -98,8 +98,7 @@ LOOLSession::LOOLSession(const std::string& id, const Kind kind,
 
 LOOLSession::~LOOLSession()
 {
-    if (_ws)
-        Util::shutdownWebSocket(*_ws);
+    Util::shutdownWebSocket(_ws);
 }
 
 void LOOLSession::sendTextFrame(const std::string& text)
@@ -183,12 +182,14 @@ void LOOLSession::disconnect(const std::string& reason)
     {
         sendTextFrame("disconnect " + reason);
         _disconnected = true;
+        Util::shutdownWebSocket(_ws);
     }
 }
 
 bool LOOLSession::handleDisconnect(Poco::StringTokenizer& /*tokens*/)
 {
     _disconnected = true;
+    Util::shutdownWebSocket(_ws);
     return false;
 }
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 370202b..a2be65d 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -763,7 +763,7 @@ void MasterProcessSession::dispatchChild()
     if (nRequest < 0 && !bFound)
     {
         Log::error(getName() + ": Failed to connect to child. Shutting down socket.");
-        Util::shutdownWebSocket(*_ws);
+        Util::shutdownWebSocket(_ws);
         return;
     }
 
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index ec8d9b9..872219a 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -279,15 +279,16 @@ namespace Util
         return true;
     }
 
-    void shutdownWebSocket(Poco::Net::WebSocket& ws)
+    void shutdownWebSocket(std::shared_ptr<Poco::Net::WebSocket> ws)
     {
         try
         {
-            ws.shutdown();
+            if (ws)
+                ws->shutdown();
         }
         catch (const Poco::IOException& exc)
         {
-            Log::error("IOException: " + exc.message());
+            Log::warn("IOException while socket shutdown: " + exc.message());
         }
     }
 
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 1e50562..eff40bd 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -13,6 +13,7 @@
 #include <string>
 #include <sstream>
 #include <functional>
+#include <memory>
 
 #include <Poco/File.h>
 #include <Poco/Path.h>
@@ -56,8 +57,8 @@ namespace Util
                               int bufferWidth, int bufferHeight,
                               std::vector<char>& output, LibreOfficeKitTileMode mode);
 
-    // Call WebSocket::shutdown() ignoring Poco::IOException
-    void shutdownWebSocket(Poco::Net::WebSocket& ws);
+    /// Call WebSocket::shutdown() ignoring Poco::IOException.
+    void shutdownWebSocket(std::shared_ptr<Poco::Net::WebSocket> ws);
 
     ssize_t writeFIFO(const int nPipe, const char* pBuffer, ssize_t nSize);
     inline


More information about the Libreoffice-commits mailing list