[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/LOOLSession.hpp loolwsd/PrisonerSession.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sat May 21 03:26:33 UTC 2016


 loolwsd/ClientSession.cpp   |   17 +----------------
 loolwsd/LOOLSession.hpp     |   22 ++++++++++++++++++++++
 loolwsd/PrisonerSession.cpp |   16 +---------------
 3 files changed, 24 insertions(+), 31 deletions(-)

New commits:
commit 7f62bb54fd07fad0dabd6ea52ba92dc827b1bbe5
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri May 20 17:42:14 2016 -0400

    loolwsd: unified forwardToPeer
    
    Change-Id: Ib12626adad1ff3cf647d6a32f9b1eae35f794b2f
    Reviewed-on: https://gerrit.libreoffice.org/25238
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 32c7f67..c951181 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -409,22 +409,7 @@ void ClientSession::sendCombinedTiles(const char* /*buffer*/, int /*length*/, St
 
 void ClientSession::forwardToPeer(const char *buffer, int length)
 {
-    const auto message = getAbbreviatedMessage(buffer, length);
-
-    auto peer = _peer.lock();
-    if (!peer)
-    {
-        throw Poco::ProtocolException(getName() + ": no peer to forward to: [" + message + "].");
-    }
-
-    if (peer->isCloseFrame())
-    {
-        Log::trace(getName() + ": peer began the closing handshake. Dropping forward message [" + message + "].");
-        return;
-    }
-
-    Log::trace(getName() + " -> " + peer->getName() + ": " + message);
-    peer->sendBinaryFrame(buffer, length);
+    LOOLSession::forwardToPeer(_peer, buffer, length);
 }
 
 bool ClientSession::shutdownPeer(Poco::UInt16 statusCode, const std::string& message)
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index c262e0d..cf75433 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -24,7 +24,9 @@
 #include <Poco/Types.h>
 
 #include "MessageQueue.hpp"
+#include "LOOLProtocol.hpp"
 #include "TileCache.hpp"
+#include "Log.hpp"
 
 class LOOLSession
 {
@@ -92,6 +94,26 @@ protected:
         _lastActivityTime = std::chrono::steady_clock::now();
     }
 
+    template <typename T>
+    void forwardToPeer(T& p, const char *buffer, int length)
+    {
+        const auto message = LOOLProtocol::getAbbreviatedMessage(buffer, length);
+
+        auto peer = p.lock();
+        if (!peer)
+        {
+            throw Poco::ProtocolException(getName() + ": no peer to forward to: [" + message + "].");
+        }
+        else if (peer->isCloseFrame())
+        {
+            Log::trace(getName() + ": peer began the closing handshake. Dropping forward message [" + message + "].");
+            return;
+        }
+
+        Log::trace(getName() + " -> " + peer->getName() + ": " + message);
+        peer->sendBinaryFrame(buffer, length);
+    }
+
     // Fields common to sessions in master and jailed processes:
 
     // Our kind signifies to what we are connected to.
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 41ad29d..bac4b6b 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -225,21 +225,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
 
 void PrisonerSession::forwardToPeer(const char *buffer, int length)
 {
-    const auto message = getAbbreviatedMessage(buffer, length);
-
-    auto peer = _peer.lock();
-    if (!peer)
-    {
-        throw Poco::ProtocolException(getName() + ": no peer to forward to: [" + message + "].");
-    }
-    else if (peer->isCloseFrame())
-    {
-        Log::trace(getName() + ": peer began the closing handshake. Dropping forward message [" + message + "].");
-        return;
-    }
-
-    Log::trace(getName() + " -> " + peer->getName() + ": " + message);
-    peer->sendBinaryFrame(buffer, length);
+    LOOLSession::forwardToPeer(_peer, buffer, length);
 }
 
 bool PrisonerSession::shutdownPeer(Poco::UInt16 statusCode, const std::string& message)


More information about the Libreoffice-commits mailing list