loolwsd/Common.hpp | 2 +- loolwsd/IoUtil.cpp | 20 ++++---------------- loolwsd/IoUtil.hpp | 22 +++++++--------------- loolwsd/LOOLWSD.cpp | 2 +- 4 files changed, 13 insertions(+), 33 deletions(-)
New commits: commit a1f4ded793b2b52e5ad98c5cb2836eb4fbd44738 Author: Tor Lillqvist <t...@collabora.com> Date: Mon Apr 11 11:28:10 2016 +0300 YAGNI: Drop parameter with default value that is never overridden No non-default value is never passed. Just use the default value as such in the function. diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index 6ffdcd4..4dacbb4 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -259,8 +259,7 @@ ssize_t readFIFO(int pipe, char* buffer, ssize_t size) /// Returns 0 for timeout, <0 for error, and >0 on success. /// On success, line will contain the read message. int PipeReader::readLine(std::string& line, - std::function<bool()> stopPredicate, - const size_t timeoutMs) + std::function<bool()> stopPredicate) { const char *endOfLine = static_cast<const char *>(std::memchr(_data.data(), '\n', _data.size())); if (endOfLine != nullptr) @@ -275,7 +274,7 @@ int PipeReader::readLine(std::string& line, // Poll in short intervals to check for stop condition. const auto pollTimeoutMs = 500; - auto maxPollCount = timeoutMs / pollTimeoutMs; + auto maxPollCount = POLL_TIMEOUT_MS / pollTimeoutMs; while (maxPollCount-- > 0) { if (stopPredicate()) @@ -339,11 +338,10 @@ int PipeReader::readLine(std::string& line, } bool PipeReader::processOnce(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate, - const size_t pollTimeoutMs) + std::function<bool()> stopPredicate) { std::string line; - const auto ready = readLine(line, stopPredicate, pollTimeoutMs); + const auto ready = readLine(line, stopPredicate); if (ready == 0) { // Timeout. diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp index 494f2a2..10078bb 100644 --- a/loolwsd/IoUtil.hpp +++ b/loolwsd/IoUtil.hpp @@ -55,16 +55,14 @@ namespace IoUtil /// to check for termination condition. /// Intended to be called from a polling loop. bool processOnce(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate, - const size_t pollTimeoutMs = POLL_TIMEOUT_MS); + std::function<bool()> stopPredicate); private: /// Reads a single line from the pipe. /// Returns 0 for timeout, <0 for error, and >0 on success. /// On success, line will contain the read message. int readLine(std::string& line, - std::function<bool()> stopPredicate, - const size_t timeoutMs = POLL_TIMEOUT_MS); + std::function<bool()> stopPredicate); const std::string _name; const int _pipe; commit 6729bb7726db9aee7f5881902358065b6be67db9 Author: Tor Lillqvist <t...@collabora.com> Date: Mon Apr 11 11:23:33 2016 +0300 PipeReader::readLine() is used only internally by processOnce() diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp index 09107ea..494f2a2 100644 --- a/loolwsd/IoUtil.hpp +++ b/loolwsd/IoUtil.hpp @@ -51,13 +51,6 @@ namespace IoUtil const std::string& getName() const { return _name; } - /// Reads a single line from the pipe. - /// Returns 0 for timeout, <0 for error, and >0 on success. - /// On success, line will contain the read message. - int readLine(std::string& line, - std::function<bool()> stopPredicate, - const size_t timeoutMs = POLL_TIMEOUT_MS); - /// Processes a single line read and invoking stopPredicate /// to check for termination condition. /// Intended to be called from a polling loop. @@ -66,6 +59,13 @@ namespace IoUtil const size_t pollTimeoutMs = POLL_TIMEOUT_MS); private: + /// Reads a single line from the pipe. + /// Returns 0 for timeout, <0 for error, and >0 on success. + /// On success, line will contain the read message. + int readLine(std::string& line, + std::function<bool()> stopPredicate, + const size_t timeoutMs = POLL_TIMEOUT_MS); + const std::string _name; const int _pipe; std::string _data; commit 077a4436dfc6522ae7d3a9b6a807242ea0daccc1 Author: Tor Lillqvist <t...@collabora.com> Date: Mon Apr 11 11:21:18 2016 +0300 Bin unused function PipeReader::process() diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index e24b121..6ffdcd4 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -363,16 +363,6 @@ bool PipeReader::processOnce(std::function<bool(std::string& message)> handler, return true; } -void PipeReader::process(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate, - const size_t pollTimeoutMs) -{ - while (processOnce(handler, stopPredicate, pollTimeoutMs)) - { - // readLine will call stopPredicate, no need to do it again here. - } -} - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/IoUtil.hpp b/loolwsd/IoUtil.hpp index 4ad06f5..09107ea 100644 --- a/loolwsd/IoUtil.hpp +++ b/loolwsd/IoUtil.hpp @@ -65,12 +65,6 @@ namespace IoUtil std::function<bool()> stopPredicate, const size_t pollTimeoutMs = POLL_TIMEOUT_MS); - /// Designed to be called from a dedicated thread, - /// blocks and processes pipe messages in a loop. - void process(std::function<bool(std::string& message)> handler, - std::function<bool()> stopPredicate, - const size_t pollTimeoutMs = POLL_TIMEOUT_MS); - private: const std::string _name; const int _pipe; commit 2623208c8fc7bcd988ed536d252ed610bcf6e3d1 Author: Tor Lillqvist <t...@collabora.com> Date: Mon Apr 11 11:17:27 2016 +0300 Rename MAINTENANCE_INTERVAL to something more descriptive diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp index 1984f4d..16b3594 100644 --- a/loolwsd/Common.hpp +++ b/loolwsd/Common.hpp @@ -18,7 +18,7 @@ constexpr int MAX_SESSIONS = 1024; constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980; constexpr int MASTER_PORT_NUMBER = 9981; -constexpr int MAINTENANCE_INTERVAL = 1; +constexpr int WSD_SLEEP_SECS = 2; constexpr int CHILD_TIMEOUT_SECS = 10; constexpr int POLL_TIMEOUT_MS = 1000; constexpr int COMMAND_TIMEOUT_MS = 5000; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index e5ee864..2c2653b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1579,7 +1579,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) last30SecCheck = time(nullptr); } } - sleep(MAINTENANCE_INTERVAL*2); + sleep(WSD_SLEEP_SECS); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits