[Libreoffice-commits] online.git: loolwsd/IoUtil.cpp loolwsd/IoUtil.hpp loolwsd/LOOLWebSocket.hpp loolwsd/Makefile.am

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Nov 14 05:19:43 UTC 2016


 loolwsd/IoUtil.cpp        |   24 +-----------------------
 loolwsd/IoUtil.hpp        |    5 -----
 loolwsd/LOOLWebSocket.hpp |   25 +++++++++++++++++++++++++
 loolwsd/Makefile.am       |    2 +-
 4 files changed, 27 insertions(+), 29 deletions(-)

New commits:
commit 0506cbb5c4bc3eaa708b92ea88ee1a02f1e4502e
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Nov 12 13:12:26 2016 -0500

    loolwsd: move reveiveFrame from IoUtil to LOOLWebSocket
    
    Change-Id: I82b64d16e496f104c34eeddce1ef9a1e57bc03bc
    Reviewed-on: https://gerrit.libreoffice.org/30816
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp
index 75b7026..918cc54 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -38,28 +38,6 @@ using Poco::Net::WebSocket;
 namespace IoUtil
 {
 
-int receiveFrame(LOOLWebSocket& socket, void* buffer, int length, int& flags)
-{
-    while (!TerminationFlag)
-    {
-        int n = socket.receiveFrame(buffer, length, flags);
-        if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_PING)
-        {
-            socket.sendFrame(buffer, n, WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_PONG);
-        }
-        else if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_PONG)
-        {
-            // In case we do send pongs in the future.
-        }
-        else
-        {
-            return n;
-        }
-    }
-
-    return -1;
-}
-
 // Synchronously process LOOLWebSocket requests and dispatch to handler.
 // Handler returns false to end.
 void SocketProcessor(const std::shared_ptr<LOOLWebSocket>& ws,
@@ -100,7 +78,7 @@ void SocketProcessor(const std::shared_ptr<LOOLWebSocket>& ws,
             payload.resize(payload.capacity());
             try
             {
-                n = receiveFrame(*ws, payload.data(), payload.capacity(), flags);
+                n = ws->receiveFrame(payload.data(), payload.capacity(), flags);
             }
             catch (const Poco::TimeoutException&)
             {
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index dba0aa7..fca3107 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -18,11 +18,6 @@
 
 namespace IoUtil
 {
-    // Wrapper for LOOLWebSocket::receiveFrame() that handles PING frames (by replying with a
-    // PONG frame) and PONG frames. PONG frames are ignored.
-    // Should we also factor out the handling of non-final and continuation frames into this?
-    // TODO: move this to LOOLWebSocket directly
-    int receiveFrame(LOOLWebSocket& socket, void* buffer, int length, int& flags);
 
     /// Synchronously process LOOLWebSocket requests and dispatch to handler.
     /// Handler returns false to end.
diff --git a/loolwsd/LOOLWebSocket.hpp b/loolwsd/LOOLWebSocket.hpp
index a8599f2..212990a 100644
--- a/loolwsd/LOOLWebSocket.hpp
+++ b/loolwsd/LOOLWebSocket.hpp
@@ -48,6 +48,31 @@ public:
     {
     }
 
+    // Wrapper for LOOLWebSocket::receiveFrame() that handles PING frames (by replying with a
+    // PONG frame) and PONG frames. PONG frames are ignored.
+    // Should we also factor out the handling of non-final and continuation frames into this?
+    int receiveFrame(char* buffer, int length, int& flags)
+    {
+        for (;;)
+        {
+            const int n = Poco::Net::WebSocket::receiveFrame(buffer, length, flags);
+            if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_PING)
+            {
+                sendFrame(buffer, n, WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_PONG);
+            }
+            else if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_PONG)
+            {
+                // In case we do send pongs in the future.
+            }
+            else
+            {
+                return n;
+            }
+        }
+
+        return -1;
+    }
+
     /// Careful - sendFrame is _not_ virtual, we need to make sure that we use
     /// LOOLWebSocket all over the place
     /// It would be a kind of more natural to encapsulate Poco::Net::WebSocket
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index 9ab1f10..fd0efdc 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -83,7 +83,7 @@ looltool_SOURCES = LOOLTool.cpp
 loolstress_CPPFLAGS = -DTDOC=\"$(abs_top_srcdir)/test/data\"
 loolstress_SOURCES = LOOLStress.cpp \
                      LOOLProtocol.cpp \
-		     Log.cpp
+                     Log.cpp
 
 noinst_HEADERS = Admin.hpp \
                  AdminModel.hpp \


More information about the Libreoffice-commits mailing list