[Libreoffice-commits] online.git: loolwsd/IoUtil.cpp loolwsd/IoUtil.hpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Apr 15 11:54:48 UTC 2016


 loolwsd/IoUtil.cpp  |   18 -----------------
 loolwsd/IoUtil.hpp  |    1 
 loolwsd/LOOLKit.cpp |   53 +++++++---------------------------------------------
 loolwsd/LOOLWSD.cpp |    6 ++---
 4 files changed, 11 insertions(+), 67 deletions(-)

New commits:
commit 7df929cb7762e8d596d30ae7f28bec5302cdd1dd
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Apr 14 23:12:25 2016 -0400

    loolwsd: use SocketProcessor in kit
    
    SocketProcessor doesn't need to take response
    instance, since by the time it is called we
    are already upgraded to WebSocket and it's
    too late to set a request-level status.
    
    Change-Id: Id95087e60354a50148c88427130613356679cf82
    Reviewed-on: https://gerrit.libreoffice.org/24110
    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 081e13e..f024055 100644
--- a/loolwsd/IoUtil.cpp
+++ b/loolwsd/IoUtil.cpp
@@ -18,7 +18,6 @@
 #include <string>
 
 #include <Poco/StringTokenizer.h>
-#include <Poco/Net/HTTPServerResponse.h>
 #include <Poco/Net/Socket.h>
 #include <Poco/Net/WebSocket.h>
 #include <Poco/Net/NetException.h>
@@ -41,7 +40,6 @@ namespace IoUtil
 // Synchronously process WebSocket requests and dispatch to handler.
 // Handler returns false to end.
 void SocketProcessor(std::shared_ptr<WebSocket> ws,
-                     Poco::Net::HTTPResponse& response,
                      std::function<bool(const std::vector<char>&)> handler,
                      std::function<bool()> stopPredicate)
 {
@@ -168,22 +166,6 @@ void SocketProcessor(std::shared_ptr<WebSocket> ws,
                       " bytes) will not be processed: [" + msg + "].");
         }
     }
-    catch (const WebSocketException& exc)
-    {
-        Log::error("SocketProcessor: WebSocketException: " + exc.message());
-        switch (exc.code())
-        {
-        case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
-            response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
-            // fallthrough
-        case WebSocket::WS_ERR_NO_HANDSHAKE:
-        case WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
-        case WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
-            response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST);
-            response.setContentLength(0);
-            break;
-        }
-    }
     catch (const Poco::Exception& exc)
     {
         Log::error("SocketProcessor: Exception: " + exc.message());
diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp
index 10078bb..a9ed2ef 100644
--- a/loolwsd/IoUtil.hpp
+++ b/loolwsd/IoUtil.hpp
@@ -24,7 +24,6 @@ namespace IoUtil
     /// Synchronously process WebSocket requests and dispatch to handler.
     //. Handler returns false to end.
     void SocketProcessor(std::shared_ptr<Poco::Net::WebSocket> ws,
-                         Poco::Net::HTTPResponse& response,
                          std::function<bool(const std::vector<char>&)> handler,
                          std::function<bool()> stopPredicate);
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index ce32008..7f63ace 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -266,18 +266,6 @@ public:
         }
     }
 
-    void handle(std::shared_ptr<TileQueue> queue, const std::string& firstLine, char* buffer, int n)
-    {
-        if (firstLine.find("paste") != 0)
-        {
-            // Everything else is expected to be a single line.
-            assert(firstLine.size() == static_cast<std::string::size_type>(n));
-            queue->put(firstLine);
-        }
-        else
-            queue->put(std::string(buffer, n));
-    }
-
     void run() override
     {
         Util::setThreadName("kit_ws_" + _session->getId());
@@ -292,38 +280,13 @@ public:
             Thread queueHandlerThread;
             queueHandlerThread.start(handler);
 
-            int flags;
-            int n;
-            do
-            {
-                char buffer[1024];
-                n = _ws->receiveFrame(buffer, sizeof(buffer), flags);
-                if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+            IoUtil::SocketProcessor(_ws,
+                    [&queue](const std::vector<char>& payload)
                 {
-                    std::string firstLine = getFirstLine(buffer, n);
-                    StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-
-                    // Check if it is a "nextmessage:" and in that case read the large
-                    // follow-up message separately, and handle that only.
-                    int size;
-                    if (tokens.count() == 2 && tokens[0] == "nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
-                    {
-                        char largeBuffer[size];
-                        n = _ws->receiveFrame(largeBuffer, size, flags);
-                        if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
-                        {
-                            firstLine = getFirstLine(largeBuffer, n);
-                            handle(queue, firstLine, largeBuffer, n);
-                        }
-                    }
-                    else
-                        handle(queue, firstLine, buffer, n);
-                }
-            }
-            while (!_stop && n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
-            Log::debug() << "Finishing. stop " << _stop
-                         << ", payload size: " << n
-                         << ", flags: " << std::hex << flags << Log::end;
+                    queue->put(payload);
+                    return true;
+                },
+                []() { return TerminationFlag; });
 
             queue->clear();
             queue->put("eof");
@@ -1006,8 +969,8 @@ void lokit_main(const std::string& childRoot,
         ws->setReceiveTimeout(0);
 
         const std::string socketName = "ChildControllerWS";
-        IoUtil::SocketProcessor(ws, response,
-                                [&socketName, &ws, &document, &loKit](const std::vector<char>& data)
+        IoUtil::SocketProcessor(ws,
+                [&socketName, &ws, &document, &loKit](const std::vector<char>& data)
                 {
                     std::string message(data.data(), data.size());
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index cbf3cce..9d14ca9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -590,8 +590,8 @@ private:
         Thread queueHandlerThread;
         queueHandlerThread.start(handler);
 
-        IoUtil::SocketProcessor(ws, response,
-                [&session, &queue](const std::vector<char>& payload)
+        IoUtil::SocketProcessor(ws,
+            [&queue](const std::vector<char>& payload)
             {
                 queue->put(payload);
                 return true;
@@ -896,7 +896,7 @@ public:
             // Now the bridge beetween the prison and the client is connected
             // Let messages flow
 
-            IoUtil::SocketProcessor(ws, response,
+            IoUtil::SocketProcessor(ws,
                     [&session](const std::vector<char>& payload)
                 {
                     return session->handleInput(payload.data(), payload.size());


More information about the Libreoffice-commits mailing list