Sync changes with proxy.

This commit is contained in:
XMRig
2020-03-08 02:43:16 +07:00
parent 6cb27e9662
commit e8355e1a1c
2 changed files with 38 additions and 6 deletions

View File

@ -25,6 +25,24 @@
#include <uv.h>
namespace xmrig {
static void fsWriteCallback(uv_fs_t *req)
{
delete [] static_cast<char *>(req->data);
uv_fs_req_cleanup(req);
delete req;
}
static const char *kNewLine = "\n";
} // namespace xmrig
bool xmrig::FileLogWriter::open(const char *fileName)
{
assert(fileName != nullptr);
@ -52,12 +70,25 @@ bool xmrig::FileLogWriter::write(const char *data, size_t size)
auto req = new uv_fs_t;
req->data = buf.base;
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, [](uv_fs_t *req) {
delete [] static_cast<char *>(req->data);
uv_fs_req_cleanup(req);
delete req;
});
uv_fs_write(uv_default_loop(), req, m_file, &buf, 1, -1, fsWriteCallback);
return true;
}
bool xmrig::FileLogWriter::writeLine(const char *data, size_t size)
{
uv_buf_t buf[2] = {
uv_buf_init(new char[size], size),
uv_buf_init(const_cast<char *>(kNewLine), 1)
};
memcpy(buf[0].base, data, size);
auto req = new uv_fs_t;
req->data = buf[0].base;
uv_fs_write(uv_default_loop(), req, m_file, buf, 2, -1, fsWriteCallback);
return true;
}

View File

@ -36,6 +36,7 @@ public:
bool open(const char *fileName);
bool write(const char *data, size_t size);
bool writeLine(const char *data, size_t size);
private:
int m_file = -1;