[Libreoffice-commits] online.git: net/Socket.hpp net/WebSocketHandler.hpp tools/WebSocketDump.cpp wsd/LOOLWSD.cpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 25 14:39:22 UTC 2018


 net/Socket.hpp           |   20 ++++++++++++--------
 net/WebSocketHandler.hpp |   24 ++++++++++++------------
 tools/WebSocketDump.cpp  |    2 +-
 wsd/LOOLWSD.cpp          |   12 ++++++------
 4 files changed, 31 insertions(+), 27 deletions(-)

New commits:
commit 4724aa0cf78f3aedf7f7f4222d251ef8395d5523
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Oct 25 16:38:54 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Oct 25 16:39:02 2018 +0200

    Socket: do what the TODO says
    
    Drop the list of friends and just add getters for the relevant
    members.

diff --git a/net/Socket.hpp b/net/Socket.hpp
index 2d8a2f26a..698edd328 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -938,6 +938,16 @@ public:
         return _clientAddress;
     }
 
+    std::vector<char>& getInBuffer()
+    {
+        return _inBuffer;
+    }
+
+    std::vector<char>& getOutBuffer()
+    {
+        return _outBuffer;
+    }
+
 protected:
 
     /// Called when a polling event is received.
@@ -1012,6 +1022,7 @@ protected:
             disposition.setClosed();
     }
 
+public:
     /// Override to write data out to socket.
     virtual void writeOutgoingData()
     {
@@ -1051,6 +1062,7 @@ protected:
         while (!_outBuffer.empty());
     }
 
+protected:
     /// Override to handle reading of socket data differently.
     virtual int readData(char* buf, int len)
     {
@@ -1096,14 +1108,6 @@ protected:
 
     /// True when shutdown was requested via shutdown().
     bool _shutdownSignalled;
-
-    // To be able to access _inBuffer and _outBuffer.
-    // TODO we probably need accessors to the _inBuffer & _outBuffer
-    // instead of this many friends...
-    friend class WebSocketHandler;
-    friend class ClientRequestDispatcher;
-    friend class PrisonerRequestDispatcher;
-    friend class SimpleResponseClient;
 };
 
 enum class WSOpCode : unsigned char {
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index fcb9d3660..3b60fe9b8 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -131,7 +131,7 @@ public:
         assert(socket && "Expected a valid socket instance.");
 
         // websocket fun !
-        const size_t len = socket->_inBuffer.size();
+        const size_t len = socket->getInBuffer().size();
 
         if (len == 0)
             return false; // avoid logging.
@@ -143,7 +143,7 @@ public:
             return false;
         }
 
-        unsigned char *p = reinterpret_cast<unsigned char*>(&socket->_inBuffer[0]);
+        unsigned char *p = reinterpret_cast<unsigned char*>(&socket->getInBuffer()[0]);
         const bool fin = p[0] & 0x80;
         const WSOpCode code = static_cast<WSOpCode>(p[0] & 0x0f);
         const bool hasMask = p[1] & 0x80;
@@ -191,7 +191,7 @@ public:
             return false;
         }
 
-        LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket data of " << len << " bytes: " << Util::stringifyHexLine(socket->_inBuffer, 0, std::min((size_t)32, len)));
+        LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket data of " << len << " bytes: " << Util::stringifyHexLine(socket->getInBuffer(), 0, std::min((size_t)32, len)));
 
         data = p + headerLen;
 
@@ -214,14 +214,14 @@ public:
 
         assert(_wsPayload.size() >= payloadLen);
 
-        socket->_inBuffer.erase(socket->_inBuffer.begin(), socket->_inBuffer.begin() + headerLen + payloadLen);
+        socket->getInBuffer().erase(socket->getInBuffer().begin(), socket->getInBuffer().begin() + headerLen + payloadLen);
 
 #ifndef MOBILEAPP
 
         // FIXME: fin, aggregating payloads into _wsPayload etc.
         LOG_TRC("#" << socket->getFD() << ": Incoming WebSocket message code " << static_cast<unsigned>(code) <<
                 ", fin? " << fin << ", mask? " << hasMask << ", payload length: " << _wsPayload.size() <<
-                ", residual socket data: " << socket->_inBuffer.size() << " bytes.");
+                ", residual socket data: " << socket->getInBuffer().size() << " bytes.");
 
         bool doClose = false;
 
@@ -444,7 +444,7 @@ private:
             return 0;
 
         socket->assertCorrectThread();
-        std::vector<char>& out = socket->_outBuffer;
+        std::vector<char>& out = socket->getOutBuffer();
         const size_t oldSize = out.size();
 
 #ifndef MOBILEAPP
@@ -586,26 +586,26 @@ protected:
     {
         std::shared_ptr<StreamSocket> socket = _socket.lock();
 
-        LOG_TRC("Incoming client websocket upgrade response: " << std::string(&socket->_inBuffer[0], socket->_inBuffer.size()));
+        LOG_TRC("Incoming client websocket upgrade response: " << std::string(&socket->getInBuffer()[0], socket->getInBuffer().size()));
 
         bool bOk = false;
         size_t responseSize = 0;
 
         try
         {
-            Poco::MemoryInputStream message(&socket->_inBuffer[0], socket->_inBuffer.size());;
+            Poco::MemoryInputStream message(&socket->getInBuffer()[0], socket->getInBuffer().size());;
             Poco::Net::HTTPResponse response;
 
             response.read(message);
 
             {
                 static const std::string marker("\r\n\r\n");
-                auto itBody = std::search(socket->_inBuffer.begin(),
-                                          socket->_inBuffer.end(),
+                auto itBody = std::search(socket->getInBuffer().begin(),
+                                          socket->getInBuffer().end(),
                                           marker.begin(), marker.end());
 
-                if (itBody != socket->_inBuffer.end())
-                    responseSize = itBody - socket->_inBuffer.begin() + marker.size();
+                if (itBody != socket->getInBuffer().end())
+                    responseSize = itBody - socket->getInBuffer().begin() + marker.size();
             }
 
             if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_SWITCHING_PROTOCOLS &&
diff --git a/tools/WebSocketDump.cpp b/tools/WebSocketDump.cpp
index fa0c1af43..39212b7e0 100644
--- a/tools/WebSocketDump.cpp
+++ b/tools/WebSocketDump.cpp
@@ -71,7 +71,7 @@ private:
     void handleIncomingMessage(SocketDisposition &disposition) override
     {
         std::shared_ptr<StreamSocket> socket = _socket.lock();
-        std::vector<char>& in = socket->_inBuffer;
+        std::vector<char>& in = socket->getInBuffer();
         LOG_TRC("#" << socket->getFD() << " handling incoming " << in.size() << " bytes.");
 
         // Find the end of the header, if any.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 30bd1b965..3f3748247 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1786,8 +1786,8 @@ private:
 
         std::shared_ptr<StreamSocket> socket = getSocket().lock();
 
-        Poco::MemoryInputStream message(&socket->_inBuffer[0],
-                                        socket->_inBuffer.size());;
+        Poco::MemoryInputStream message(&socket->getInBuffer()[0],
+                                        socket->getInBuffer().size());;
         Poco::Net::HTTPRequest request;
         size_t requestSize = 0;
 
@@ -1837,7 +1837,7 @@ private:
                 return;
             }
 
-            socket->_inBuffer.clear();
+            socket->getInBuffer().clear();
 
             LOG_INF("New child [" << pid << "], jailId: " << jailId << ".");
 
@@ -1987,8 +1987,8 @@ private:
         std::shared_ptr<StreamSocket> socket = _socket.lock();
 
 #ifndef MOBILEAPP
-        Poco::MemoryInputStream message(&socket->_inBuffer[0],
-                                        socket->_inBuffer.size());;
+        Poco::MemoryInputStream message(&socket->getInBuffer()[0],
+                                        socket->getInBuffer().size());;
         Poco::Net::HTTPRequest request;
         size_t requestSize = 0;
 
@@ -2100,7 +2100,7 @@ private:
 
             // NOTE: Check _wsState to choose between HTTP response or WebSocket (app-level) error.
             LOG_INF("#" << socket->getFD() << " Exception while processing incoming request: [" <<
-                    LOOLProtocol::getAbbreviatedMessage(socket->_inBuffer) << "]: " << exc.what());
+                    LOOLProtocol::getAbbreviatedMessage(socket->getInBuffer()) << "]: " << exc.what());
         }
 
         // if we succeeded - remove the request from our input buffer


More information about the Libreoffice-commits mailing list