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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue May 17 03:23:00 UTC 2016


 loolwsd/ClientSession.cpp        |   36 ++++++++++++++++++++++++++++++------
 loolwsd/ClientSession.hpp        |   13 ++++---------
 loolwsd/LOOLSession.hpp          |    5 +++++
 loolwsd/LOOLWSD.cpp              |    2 +-
 loolwsd/MasterProcessSession.cpp |   29 -----------------------------
 loolwsd/MasterProcessSession.hpp |    3 +--
 loolwsd/PrisonerSession.cpp      |   31 ++++++++++++++++++++++++++++++-
 loolwsd/PrisonerSession.hpp      |   14 +++++---------
 8 files changed, 76 insertions(+), 57 deletions(-)

New commits:
commit d1d5cff3e36ed50f251215d72f054101dfa72352
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 16 22:48:33 2016 -0400

    loolwsd: MasterProcessSession splitting: moved forwarding and shutdown
    
    Change-Id: I3c84d9be328e58263cac9c3b1b501ef91ea30170
    Reviewed-on: https://gerrit.libreoffice.org/25048
    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 a1a6dca..c1f4023 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -37,7 +37,7 @@ ClientSession::ClientSession(const std::string& id,
                              std::shared_ptr<Poco::Net::WebSocket> ws,
                              std::shared_ptr<DocumentBroker> docBroker,
                              std::shared_ptr<BasicTileQueue> queue) :
-    MasterProcessSession(id, Kind::ToClient, ws),
+    LOOLSession(id, Kind::ToClient, ws),
     _docBroker(docBroker),
     _queue(queue),
     _loadFailed(false),
@@ -54,11 +54,6 @@ ClientSession::~ClientSession()
     _saveAsQueue.put("");
 }
 
-void ClientSession::setPeer(const std::shared_ptr<PrisonerSession>& peer)
-{
-    MasterProcessSession::_peer = _peer = peer;
-}
-
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
     const std::string firstLine = getFirstLine(buffer, length);
@@ -432,4 +427,33 @@ void ClientSession::dispatchChild()
     forwardToPeer(loadRequest.c_str(), loadRequest.size());
 }
 
+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 + "].");
+    }
+    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);
+}
+
+bool ClientSession::shutdownPeer(Poco::UInt16 statusCode, const std::string& message)
+{
+    auto peer = _peer.lock();
+    if (peer && !peer->isCloseFrame())
+    {
+        peer->shutdown(statusCode, message);
+    }
+    return peer != nullptr;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index 976b9c6..b884e72 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -21,7 +21,7 @@
 class DocumentBroker;
 class PrisonerSession;
 
-class ClientSession final : public MasterProcessSession, public std::enable_shared_from_this<ClientSession>
+class ClientSession final : public LOOLSession, public std::enable_shared_from_this<ClientSession>
 {
 public:
     ClientSession(const std::string& id,
@@ -35,7 +35,8 @@ public:
     void markEditLock(const bool value) { _bEditLock = value; }
     bool isEditLocked() const { return _bEditLock; }
 
-    void setPeer(const std::shared_ptr<PrisonerSession>& peer);
+    void setPeer(const std::shared_ptr<PrisonerSession>& peer) { _peer = peer; }
+    bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
     /**
      * Return the URL of the saved-as document when it's ready. If called
@@ -81,6 +82,7 @@ private:
     void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens);
 
     void dispatchChild();
+    void forwardToPeer(const char *buffer, int length);
 
 private:
 
@@ -101,13 +103,6 @@ private:
     /// Marks if document loading failed.
     bool _loadFailed;
     int _loadPart;
-
-#if 0
-    bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
-
- private:
-    void forwardToPeer(const char *buffer, int length);
-#endif
 };
 
 #endif
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 137a0d9..2e561f9 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -50,6 +50,11 @@ public:
     /// Called to handle disconnection command from socket.
     virtual bool handleDisconnect();
 
+    void shutdown(Poco::UInt16 statusCode, const std::string& message)
+    {
+        _ws->shutdown(statusCode, message);
+    }
+
     bool isActive() const { return _isActive; }
     void setIsActive(bool active) { _isActive = active; }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3e922b0..34da033 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -317,7 +317,7 @@ public:
 class ClientRequestHandler: public HTTPRequestHandler
 {
 private:
-    static void waitBridgeCompleted(const std::shared_ptr<MasterProcessSession>& session)
+    static void waitBridgeCompleted(const std::shared_ptr<ClientSession>& session)
     {
         bool isFound = false;
         std::unique_lock<std::mutex> lock(AvailableChildSessionMutex);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 84c7717..6f77822 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -43,33 +43,4 @@ MasterProcessSession::~MasterProcessSession()
 {
 }
 
-void MasterProcessSession::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);
-}
-
-bool MasterProcessSession::shutdownPeer(Poco::UInt16 statusCode, const std::string& message)
-{
-    auto peer = _peer.lock();
-    if (peer && !peer->isCloseFrame())
-    {
-        peer->_ws->shutdown(statusCode, message);
-    }
-    return peer != nullptr;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index bf860d9..e284c2e 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -26,11 +26,10 @@ class MasterProcessSession : public LOOLSession
                          const Kind kind,
                          std::shared_ptr<Poco::Net::WebSocket> ws);
     virtual ~MasterProcessSession();
-
+ private:
     bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
  protected:
-    void dispatchChild();
     void forwardToPeer(const char *buffer, int length);
 
     // If _kind==ToPrisoner and the child process has started and completed its handshake with the
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 30e0f23..f7388a4 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -36,7 +36,7 @@ using Poco::StringTokenizer;
 PrisonerSession::PrisonerSession(const std::string& id,
                                  std::shared_ptr<Poco::Net::WebSocket> ws,
                                  std::shared_ptr<DocumentBroker> docBroker) :
-    MasterProcessSession(id, Kind::ToPrisoner, ws),
+    LOOLSession(id, Kind::ToPrisoner, ws),
     _docBroker(docBroker),
     _curPart(0)
 {
@@ -223,4 +223,33 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
     return true;
 }
 
+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);
+}
+
+bool PrisonerSession::shutdownPeer(Poco::UInt16 statusCode, const std::string& message)
+{
+    auto peer = _peer.lock();
+    if (peer && !peer->isCloseFrame())
+    {
+        peer->shutdown(statusCode, message);
+    }
+    return peer != nullptr;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/PrisonerSession.hpp b/loolwsd/PrisonerSession.hpp
index 553d204..e0beb87 100644
--- a/loolwsd/PrisonerSession.hpp
+++ b/loolwsd/PrisonerSession.hpp
@@ -21,7 +21,7 @@
 class DocumentBroker;
 class ClientSession;
 
-class PrisonerSession final : public MasterProcessSession, public std::enable_shared_from_this<PrisonerSession>
+class PrisonerSession final : public LOOLSession, public std::enable_shared_from_this<PrisonerSession>
 {
 public:
     PrisonerSession(const std::string& id,
@@ -30,24 +30,20 @@ public:
 
     virtual ~PrisonerSession();
 
-    void setPeer(const std::shared_ptr<ClientSession>& peer) { MasterProcessSession::_peer = _peer = peer; }
+    void setPeer(const std::shared_ptr<ClientSession>& peer) { _peer = peer; }
+    bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
 private:
 
     virtual bool _handleInput(const char *buffer, int length) override;
 
+    void forwardToPeer(const char *buffer, int length);
+
 private:
 
     std::shared_ptr<DocumentBroker> _docBroker;
     std::weak_ptr<ClientSession> _peer;
     int _curPart;
-
-#if 0
-    bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
-
- private:
-    void forwardToPeer(const char *buffer, int length);
-#endif
 };
 
 #endif


More information about the Libreoffice-commits mailing list