Removed uv_try_write for console log.

This commit is contained in:
XMRig 2019-10-06 11:03:01 +07:00
parent 59b62dcb77
commit 8af1075c98
3 changed files with 13 additions and 36 deletions

View file

@ -31,10 +31,10 @@
#include <algorithm> #include <algorithm>
#include <cstring>
#include <ctime>
#include <mutex> #include <mutex>
#include <string.h>
#include <string> #include <string>
#include <time.h>
#include <uv.h> #include <uv.h>
#include <vector> #include <vector>
@ -42,6 +42,7 @@
#include "base/io/log/Log.h" #include "base/io/log/Log.h"
#include "base/kernel/interfaces/ILogBackend.h" #include "base/kernel/interfaces/ILogBackend.h"
#include "base/tools/Chrono.h" #include "base/tools/Chrono.h"
#include "base/tools/Object.h"
namespace xmrig { namespace xmrig {
@ -67,10 +68,10 @@ static const char *colors_map[] = {
class LogPrivate class LogPrivate
{ {
public: public:
inline LogPrivate() : XMRIG_DISABLE_COPY_MOVE(LogPrivate)
m_buf()
{
} LogPrivate() = default;
inline ~LogPrivate() inline ~LogPrivate()
@ -134,7 +135,7 @@ private:
const uint64_t ms = Chrono::currentMSecsSinceEpoch(); const uint64_t ms = Chrono::currentMSecsSinceEpoch();
time_t now = ms / 1000; time_t now = ms / 1000;
tm stime; tm stime{};
# ifdef _WIN32 # ifdef _WIN32
localtime_s(&stime, &now); localtime_s(&stime, &now);
@ -188,7 +189,7 @@ private:
} }
char m_buf[4096]; char m_buf[4096]{};
std::mutex m_mutex; std::mutex m_mutex;
std::vector<ILogBackend*> m_backends; std::vector<ILogBackend*> m_backends;
}; };

View file

@ -47,7 +47,6 @@ xmrig::ConsoleLog::ConsoleLog()
} }
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL); uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
# ifdef WIN32 # ifdef WIN32
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); 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) { if (!m_tty || Log::colors != colors) {
return; return;
} }
# ifdef _WIN32 fputs(line, stdout);
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), static_cast<unsigned int>(size)); fflush(stdout);
# else
uv_buf_t buf = uv_buf_init(const_cast<char *>(line), size);
# endif
if (!isWritable()) {
fputs(line, stdout);
fflush(stdout);
}
else {
uv_try_write(m_stream, &buf, 1);
}
} }
@ -95,13 +83,3 @@ bool xmrig::ConsoleLog::isSupported() const
const uv_handle_type type = uv_guess_handle(1); const uv_handle_type type = uv_guess_handle(1);
return type == UV_TTY || type == UV_NAMED_PIPE; 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();
}

View file

@ -51,10 +51,8 @@ protected:
private: private:
bool isSupported() const; bool isSupported() const;
bool isWritable() const;
uv_stream_t *m_stream = nullptr; uv_tty_t *m_tty = nullptr;
uv_tty_t *m_tty = nullptr;
}; };