From 8af1075c9821c18272a6d8b9980b1bf62981a24f Mon Sep 17 00:00:00 2001 From: XMRig Date: Sun, 6 Oct 2019 11:03:01 +0700 Subject: [PATCH] Removed uv_try_write for console log. --- src/base/io/log/Log.cpp | 17 ++++++++------- src/base/io/log/backends/ConsoleLog.cpp | 28 +++---------------------- src/base/io/log/backends/ConsoleLog.h | 4 +--- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/src/base/io/log/Log.cpp b/src/base/io/log/Log.cpp index 250bc3c4c..2cd372423 100644 --- a/src/base/io/log/Log.cpp +++ b/src/base/io/log/Log.cpp @@ -31,10 +31,10 @@ #include +#include +#include #include -#include #include -#include #include #include @@ -42,6 +42,7 @@ #include "base/io/log/Log.h" #include "base/kernel/interfaces/ILogBackend.h" #include "base/tools/Chrono.h" +#include "base/tools/Object.h" namespace xmrig { @@ -67,10 +68,10 @@ static const char *colors_map[] = { class LogPrivate { public: - inline LogPrivate() : - m_buf() - { - } + XMRIG_DISABLE_COPY_MOVE(LogPrivate) + + + LogPrivate() = default; inline ~LogPrivate() @@ -134,7 +135,7 @@ private: const uint64_t ms = Chrono::currentMSecsSinceEpoch(); time_t now = ms / 1000; - tm stime; + tm stime{}; # ifdef _WIN32 localtime_s(&stime, &now); @@ -188,7 +189,7 @@ private: } - char m_buf[4096]; + char m_buf[4096]{}; std::mutex m_mutex; std::vector m_backends; }; diff --git a/src/base/io/log/backends/ConsoleLog.cpp b/src/base/io/log/backends/ConsoleLog.cpp index 34a7d66ba..c2cd74dce 100644 --- a/src/base/io/log/backends/ConsoleLog.cpp +++ b/src/base/io/log/backends/ConsoleLog.cpp @@ -47,7 +47,6 @@ xmrig::ConsoleLog::ConsoleLog() } uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL); - m_stream = reinterpret_cast(m_tty); # ifdef WIN32 HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); @@ -68,25 +67,14 @@ xmrig::ConsoleLog::~ConsoleLog() } -void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t size, bool colors) +void xmrig::ConsoleLog::print(int, const char *line, size_t, size_t, bool colors) { if (!m_tty || Log::colors != colors) { return; } -# ifdef _WIN32 - uv_buf_t buf = uv_buf_init(const_cast(line), static_cast(size)); -# else - uv_buf_t buf = uv_buf_init(const_cast(line), size); -# endif - - if (!isWritable()) { - fputs(line, stdout); - fflush(stdout); - } - else { - uv_try_write(m_stream, &buf, 1); - } + fputs(line, stdout); + fflush(stdout); } @@ -95,13 +83,3 @@ bool xmrig::ConsoleLog::isSupported() const const uv_handle_type type = uv_guess_handle(1); return type == UV_TTY || type == UV_NAMED_PIPE; } - - -bool xmrig::ConsoleLog::isWritable() const -{ - if (!m_stream || uv_is_writable(m_stream) != 1) { - return false; - } - - return isSupported(); -} diff --git a/src/base/io/log/backends/ConsoleLog.h b/src/base/io/log/backends/ConsoleLog.h index 6277cc7be..36610e5e8 100644 --- a/src/base/io/log/backends/ConsoleLog.h +++ b/src/base/io/log/backends/ConsoleLog.h @@ -51,10 +51,8 @@ protected: private: bool isSupported() const; - bool isWritable() const; - uv_stream_t *m_stream = nullptr; - uv_tty_t *m_tty = nullptr; + uv_tty_t *m_tty = nullptr; };