libjansson replaced to rapidjson.

Sync changes with proxy.
This commit is contained in:
XMRig 2017-10-04 23:33:30 +03:00
parent 4cf3bb9930
commit af51513614
78 changed files with 15550 additions and 6420 deletions

View file

@ -23,6 +23,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@ -38,13 +39,16 @@
ConsoleLog::ConsoleLog(bool colors) :
m_colors(colors)
m_colors(colors),
m_stream(nullptr)
{
if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) {
return;
}
uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL);
m_uvBuf.base = m_buf;
m_stream = reinterpret_cast<uv_stream_t*>(&m_tty);
# ifdef WIN32
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
@ -99,21 +103,19 @@ void ConsoleLog::message(int level, const char* fmt, va_list args)
}
}
char *buf = new char[64 + strlen(fmt) + 2];
sprintf(buf, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
stime.tm_year + 1900,
stime.tm_mon + 1,
stime.tm_mday,
stime.tm_hour,
stime.tm_min,
stime.tm_sec,
m_colors ? color : "",
fmt,
m_colors ? Log::kCL_N : ""
snprintf(m_fmt, sizeof(m_fmt) - 1, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n",
stime.tm_year + 1900,
stime.tm_mon + 1,
stime.tm_mday,
stime.tm_hour,
stime.tm_min,
stime.tm_sec,
m_colors ? color : "",
fmt,
m_colors ? Log::kCL_N : ""
);
print(buf, args);
print(args);
}
@ -123,17 +125,15 @@ void ConsoleLog::text(const char* fmt, va_list args)
return;
}
char *buf = new char[64 + strlen(fmt) + 2];
snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : "");
print(buf, args);
print(args);
}
bool ConsoleLog::isWritable() const
{
if (uv_is_writable(reinterpret_cast<const uv_stream_t*>(&m_tty)) != 1) {
if (!m_stream || uv_is_writable(m_stream) != 1) {
return false;
}
@ -142,20 +142,12 @@ bool ConsoleLog::isWritable() const
}
void ConsoleLog::print(char *fmt, va_list args)
void ConsoleLog::print(va_list args)
{
vsnprintf(m_buf, sizeof(m_buf) - 1, fmt, args);
delete [] fmt;
m_uvBuf.len = vsnprintf(m_buf, sizeof(m_buf) - 1, m_fmt, args);
if (m_uvBuf.len <= 0) {
return;
}
uv_buf_t buf;
buf.base = strdup(m_buf);
buf.len = strlen(buf.base);
uv_write_t *req = new uv_write_t;
req->data = buf.base;
uv_write(req, reinterpret_cast<uv_stream_t*>(&m_tty), &buf, 1, [](uv_write_t *req, int status) {
free(req->data);
delete req;
});
uv_try_write(m_stream, &m_uvBuf, 1);
}