net/WebSocketHandler.hpp |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 11f3a29cb2b5f5985d398ae4d7b3244d2467489f
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Fri Mar 10 14:36:21 2017 +0000

    WebSocket - several messages can appear in a single packet.

diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 333b1be..b445ac7 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -110,18 +110,18 @@ public:
     }
 
     /// Implementation of the SocketHandlerInterface.
-    virtual void handleIncomingMessage() override
+    virtual bool handleOneIncomingMessage()
     {
         auto socket = _socket.lock();
         if (socket == nullptr)
-            return;
+            return false;
 
         // websocket fun !
         const size_t len = socket->_inBuffer.size();
         LOG_TRC("Incoming WebSocket data of " << len << " bytes to socket #" 
<< socket->getFD());
 
         if (len < 2) // partial read
-            return;
+            return false;
 
         unsigned char *p = reinterpret_cast<unsigned 
char*>(&socket->_inBuffer[0]);
         bool fin = p[0] & 0x80;
@@ -134,7 +134,7 @@ public:
         if (payloadLen == 126) // 2 byte length
         {
             if (len < 2 + 2)
-                return;
+                return false;
 
             payloadLen = (((unsigned)p[2]) << 8) | ((unsigned)p[3]);
             headerLen += 2;
@@ -142,7 +142,7 @@ public:
         else if (payloadLen == 127) // 8 byte length
         {
             if (len < 2 + 8)
-                return;
+                return false;
 
             payloadLen = ((((uint64_t)p[9]) <<  0) + (((uint64_t)p[8]) <<  8) +
                           (((uint64_t)p[7]) << 16) + (((uint64_t)p[6]) << 24) +
@@ -162,7 +162,7 @@ public:
 
         if (payloadLen + headerLen > len)
         { // partial read wait for more data.
-            return;
+            return false;
         }
 
         data = p + headerLen;
@@ -209,8 +209,18 @@ public:
         }
 
         _wsPayload.clear();
+
+        return true;
     }
 
+    /// Implementation of the SocketHandlerInterface.
+    virtual void handleIncomingMessage() override
+    {
+        while (handleOneIncomingMessage() && _inBuffer.size() > 0)
+            ; // can have multiple msgs in one recv'd packet.
+    }
+
+
     bool hasQueuedWrites() const override
     {
         LOG_TRC("WebSocket - asked for queued writes");
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to