[Libreoffice-commits] online.git: net/Socket.cpp net/WebSocketHandler.hpp

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 24 11:28:07 UTC 2020


 net/Socket.cpp           |    6 ++++--
 net/WebSocketHandler.hpp |   33 ++++++++++++++++++---------------
 2 files changed, 22 insertions(+), 17 deletions(-)

New commits:
commit d664d4ab40f699d2efec34b7c2d7c99a6b18a7be
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Jun 24 13:50:08 2020 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Jun 24 13:27:47 2020 +0200

    No pinging necessary in the MOBILEAPP case
    
    There aren't multiple processes that would need to "ping" each others.
    
    Ifdef out the related member variables and code completely. Having
    them partially in caused lots of FakeSocket polling with zero timeout
    which is less than ideal.
    
    Change-Id: Ibdfa4980d6d4fc9c00ea5146ca8d75ca0df81f1d
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97021
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/net/Socket.cpp b/net/Socket.cpp
index 0d0b3ed0b..cc0e9cf64 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -525,8 +525,10 @@ const int WebSocketHandler::PingFrequencyMicroS = 18 * 1000 * 1000;
 
 void WebSocketHandler::dumpState(std::ostream& os)
 {
-    os << (_shuttingDown ? "shutd " : "alive ")
-       << std::setw(5) << _pingTimeUs/1000. << "ms ";
+    os << (_shuttingDown ? "shutd " : "alive ");
+#if !MOBILEAPP
+    os << std::setw(5) << _pingTimeUs/1000. << "ms ";
+#endif
     if (_wsPayload.size() > 0)
         Util::dumpHex(os, "\t\tws queued payload:\n", "\t\t", _wsPayload);
     os << '\n';
diff --git a/net/WebSocketHandler.hpp b/net/WebSocketHandler.hpp
index 9c4ac5bb4..4aca03e38 100644
--- a/net/WebSocketHandler.hpp
+++ b/net/WebSocketHandler.hpp
@@ -29,16 +29,16 @@ private:
     /// The socket that owns us (we can't own it).
     std::weak_ptr<StreamSocket> _socket;
 
+#if !MOBILEAPP
     std::chrono::steady_clock::time_point _lastPingSentTime;
     int _pingTimeUs;
+    bool _isMasking;
+    bool _inFragmentBlock;
+#endif
 
     std::vector<char> _wsPayload;
     std::atomic<bool> _shuttingDown;
     bool _isClient;
-#if !MOBILEAPP
-    bool _isMasking;
-    bool _inFragmentBlock;
-#endif
 
 protected:
     struct WSFrameMask
@@ -60,15 +60,15 @@ public:
     ///                 defragmentation should be handled inside message handler (true) or the message handler
     ///                 should be called after all fragments of a message were received and the message
     ///                 was defragmented (false).
-    WebSocketHandler(bool isClient = false, bool isMasking = true)
-        : _lastPingSentTime(std::chrono::steady_clock::now())
-        , _pingTimeUs(0)
-        , _shuttingDown(false)
-        , _isClient(isClient)
+    WebSocketHandler(bool isClient = false, bool isMasking = true) :
 #if !MOBILEAPP
-        , _isMasking(isClient && isMasking)
-        , _inFragmentBlock(false)
+        _lastPingSentTime(std::chrono::steady_clock::now()),
+        _pingTimeUs(0),
+        _isMasking(isClient && isMasking),
+        _inFragmentBlock(false),
 #endif
+        _shuttingDown(false),
+        _isClient(isClient)
     {
     }
 
@@ -79,16 +79,16 @@ public:
     WebSocketHandler(const std::weak_ptr<StreamSocket>& socket,
                      const Poco::Net::HTTPRequest& request)
         : _socket(socket)
+#if !MOBILEAPP
         , _lastPingSentTime(std::chrono::steady_clock::now() -
                             std::chrono::microseconds(PingFrequencyMicroS) -
                             std::chrono::microseconds(InitialPingDelayMicroS))
         , _pingTimeUs(0)
-        , _shuttingDown(false)
-        , _isClient(false)
-#if !MOBILEAPP
         , _isMasking(false)
         , _inFragmentBlock(false)
 #endif
+        , _shuttingDown(false)
+        , _isClient(false)
     {
         upgradeToWebSocket(request);
     }
@@ -430,12 +430,14 @@ public:
     int getPollEvents(std::chrono::steady_clock::time_point now,
                       int64_t & timeoutMaxMicroS) override
     {
+#if !MOBILEAPP
         if (!_isClient)
         {
             const int64_t timeSincePingMicroS =
                 std::chrono::duration_cast<std::chrono::microseconds>(now - _lastPingSentTime).count();
             timeoutMaxMicroS = std::min(timeoutMaxMicroS, PingFrequencyMicroS - timeSincePingMicroS);
         }
+#endif
         int events = POLLIN;
         if (_msgHandler && _msgHandler->hasQueuedMessages())
             events |= POLLOUT;
@@ -810,10 +812,11 @@ protected:
         std::shared_ptr<StreamSocket> socket = _socket.lock();
         if (socket)
             socket->setWebSocket();
-
+#if !MOBILEAPP
         // No need to ping right upon connection/upgrade,
         // but do reset the time to avoid pinging immediately after.
         _lastPingSentTime = std::chrono::steady_clock::now();
+#endif
     }
 };
 


More information about the Libreoffice-commits mailing list