[Libreoffice-commits] online.git: loolwsd/Connect.cpp loolwsd/LoadTest.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/test

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


 loolwsd/Connect.cpp         |    3 +--
 loolwsd/LOOLKit.cpp         |    5 ++---
 loolwsd/LOOLWSD.cpp         |   20 +++++++++++---------
 loolwsd/LoadTest.cpp        |    3 +--
 loolwsd/test/httpwstest.cpp |    4 ++--
 5 files changed, 17 insertions(+), 18 deletions(-)

New commits:
commit 291b0aac6714094050f289bc720c64ea1ee89add
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Jan 21 09:00:58 2016 -0500

    loolwsd: don't ignore the last few bytes of a closed socket
    
    Change-Id: Id6332857e49ccbacfa6e63b87a1ed570e9598147
    Reviewed-on: https://gerrit.libreoffice.org/21680
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 2f81a67..3aceeaf 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -76,8 +76,7 @@ public:
             {
                 char buffer[100000];
                 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-                if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                if (n > 0)
                 {
                     std::cout << "Got " << n << " bytes: " << getAbbreviatedMessage(buffer, n) << std::endl;
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index bceb1fa..c9160c3 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -381,8 +381,7 @@ public:
             {
                 char buffer[1024];
                 n = _ws->receiveFrame(buffer, sizeof(buffer), flags);
-
-                if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                if (n > 0)
                 {
                     std::string firstLine = getFirstLine(buffer, n);
                     if (firstLine == "eof")
@@ -410,7 +409,7 @@ public:
                         handle(queue, firstLine, buffer, n);
                 }
             }
-            while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !_stop);
+            while (!_stop && n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
             Log::debug() << "Finishing " << thread_name << ". stop " << _stop
                          << ", payload size: " << n
                          << ", flags: " << std::hex << flags << Log::end;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c0af9e3..78d53fd 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -223,8 +223,14 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
                 {
                     continue;
                 }
-                else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                else if (n <= 0)
                 {
+                    // Connection closed.
+                    break;
+                }
+                else
+                {
+                    assert(n > 0);
                     const std::string firstLine = getFirstLine(buffer, n);
                     if (firstLine == "eof")
                     {
@@ -267,13 +273,10 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
                             char largeBuffer[size];     //FIXME: Security risk! Flooding may segfault us.
 
                             n = ws->receiveFrame(largeBuffer, size, flags);
-                            if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                            if (n > 0 && !handler(largeBuffer, n, false))
                             {
-                                if (!handler(largeBuffer, n, false))
-                                {
-                                    Log::info("Socket handler flagged for finishing.");
-                                    break;
-                                }
+                                Log::info("Socket handler flagged for finishing.");
+                                break;
                             }
                         }
                         else
@@ -613,8 +616,7 @@ public:
             {
                 char buffer[200000];
                 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-                if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                if (n > 0)
                 {
                     Log::trace() << "Client got " << n << " bytes: "
                                  << getAbbreviatedMessage(buffer, n) << Log::end;
diff --git a/loolwsd/LoadTest.cpp b/loolwsd/LoadTest.cpp
index aaa2e3e..24fceec 100644
--- a/loolwsd/LoadTest.cpp
+++ b/loolwsd/LoadTest.cpp
@@ -92,8 +92,7 @@ public:
             {
                 char buffer[100000];
                 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
-
-                if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+                if (n > 0)
                 {
 #if 0
                     Log::debug() << "Client got " << n << " bytes: "
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index e18f63f..7b8d939 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -72,7 +72,7 @@ void HTTPWSTest::testPaste()
     {
         char buffer[100000];
         n = _socket.receiveFrame(buffer, sizeof(buffer), flags);
-        if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+        if (n > 0)
         {
             const std::string line = LOOLProtocol::getFirstLine(buffer, n);
             const std::string prefix = "textselectioncontent: ";
@@ -140,7 +140,7 @@ void HTTPWSTest::testRenderingOptions()
     {
         char buffer[100000];
         n = _socket.receiveFrame(buffer, sizeof(buffer), flags);
-        if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+        if (n > 0)
         {
             std::string line = LOOLProtocol::getFirstLine(buffer, n);
             std::string prefix = "status: ";


More information about the Libreoffice-commits mailing list