[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/ChildProcessSession.hpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/MasterProcessSession.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun Apr 10 03:33:16 UTC 2016
loolwsd/ChildProcessSession.cpp | 5 +++--
loolwsd/ChildProcessSession.hpp | 31 -------------------------------
loolwsd/LOOLSession.cpp | 3 ++-
loolwsd/LOOLSession.hpp | 18 ++++++++++++++++++
loolwsd/MasterProcessSession.cpp | 2 ++
5 files changed, 25 insertions(+), 34 deletions(-)
New commits:
commit b6d2edb0e30770fe2b722109af9e5cbda5c9b80d
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat Apr 9 17:47:23 2016 -0400
loolwsd: moved activity tracking into LOOLSession
Change-Id: I87d5afc43bea29ede2ad6e2871c594c4746bc3d5
Reviewed-on: https://gerrit.libreoffice.org/23948
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index ec7dc0f..62d64ab 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -308,7 +308,7 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length)
{
if (isInactive() && _loKitDocument != nullptr)
{
- Log::debug("Handling message after inactivity of " + std::to_string(_stats.getInactivityMS()) + "ms.");
+ Log::debug("Handling message after inactivity of " + std::to_string(getInactivityMS()) + "ms.");
// Client is getting active again.
// Send invalidation and other sync-up messages.
@@ -333,7 +333,8 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length)
//TODO: Sync cursor.
}
- _stats.updateLastActivityTime();
+ updateLastActivityTime();
+
const std::string firstLine = getFirstLine(buffer, length);
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp
index ab3347c..0f14842 100644
--- a/loolwsd/ChildProcessSession.hpp
+++ b/loolwsd/ChildProcessSession.hpp
@@ -30,30 +30,6 @@ class CallbackWorker;
class ChildProcessSession final : public LOOLSession
{
public:
- class Statistics
- {
- public:
- Statistics() :
- _lastActivityTime(std::chrono::steady_clock::now())
- {
- }
-
- void updateLastActivityTime()
- {
- _lastActivityTime = std::chrono::steady_clock::now();
- }
-
- double getInactivityMS() const
- {
- const auto duration = (std::chrono::steady_clock::now() - _lastActivityTime);
- return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
- }
-
- private:
- std::chrono::steady_clock::time_point _lastActivityTime;
- };
-
-public:
/// Create a new ChildProcessSession
/// ws The socket between master and kit (jailed).
/// loKit The LOKit instance.
@@ -88,9 +64,6 @@ public:
std::unique_lock<std::recursive_mutex> getLock() { return std::unique_lock<std::recursive_mutex>(Mutex); }
- const Statistics& getStatistics() const { return _stats; }
- bool isInactive() const { return _stats.getInactivityMS() >= InactivityThresholdMS; }
-
protected:
virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override;
@@ -131,8 +104,6 @@ private:
int _clientPart;
std::function<LibreOfficeKitDocument*(const std::string&, const std::string&, const std::string&, bool)> _onLoad;
std::function<void(const std::string&)> _onUnload;
- /// Statistics and activity tracking.
- Statistics _stats;
std::unique_ptr<CallbackWorker> _callbackWorker;
Poco::Thread _callbackThread;
@@ -141,8 +112,6 @@ private:
/// Synchronize _loKitDocument acess.
/// This should be owned by Document.
static std::recursive_mutex Mutex;
-
- static constexpr auto InactivityThresholdMS = 120 * 1000;
};
#endif
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index a80b65b..1fd268c 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -55,7 +55,8 @@ LOOLSession::LOOLSession(const std::string& id, const Kind kind,
_isDocPasswordProvided(false),
_isDocLoaded(false),
_isDocPasswordProtected(false),
- _disconnected(false)
+ _disconnected(false),
+ _lastActivityTime(std::chrono::steady_clock::now())
{
// Only a post request can have a null ws.
if (_kind != Kind::ToClient)
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index d5fd76b..2fc5429 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -54,6 +54,15 @@ public:
/// Called to handle disconnection command from socket.
virtual bool handleDisconnect(Poco::StringTokenizer& tokens);
+ bool isInactive() const { return getInactivityMS() >= InactivityThresholdMS; }
+
+ /// Returns the inactivity time of the client in milliseconds.
+ double getInactivityMS() const
+ {
+ const auto duration = (std::chrono::steady_clock::now() - _lastActivityTime);
+ return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+ }
+
protected:
LOOLSession(const std::string& id, const Kind kind,
std::shared_ptr<Poco::Net::WebSocket> ws);
@@ -78,6 +87,11 @@ protected:
virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0;
+ void updateLastActivityTime()
+ {
+ _lastActivityTime = std::chrono::steady_clock::now();
+ }
+
// Fields common to sessions in master and jailed processes:
// Our kind signifies to what we are connected to.
@@ -123,7 +137,11 @@ private:
/// True if we have been disconnected.
bool _disconnected;
+ std::chrono::steady_clock::time_point _lastActivityTime;
+
std::mutex _mutex;
+
+ static constexpr auto InactivityThresholdMS = 120 * 1000;
};
template<typename charT, typename traits>
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index b7cab54..4fc5ecf 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -103,6 +103,8 @@ bool MasterProcessSession::handleDisconnect(Poco::StringTokenizer& tokens)
bool MasterProcessSession::_handleInput(const char *buffer, int length)
{
+ updateLastActivityTime();
+
const std::string firstLine = getFirstLine(buffer, length);
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
Log::trace(getName() + ": handling [" + firstLine + "].");
More information about the Libreoffice-commits
mailing list