Update net

This commit is contained in:
XMRig 2020-12-02 11:32:11 +07:00
parent 121c515a07
commit 469b1f08de
No known key found for this signature in database
GPG key ID: 446A53638BE94409
14 changed files with 95 additions and 74 deletions

View file

@ -19,8 +19,9 @@
#include "base/net/tools/LineReader.h"
#include "base/net/tools/NetBuffer.h"
#include "base/kernel/constants.h"
#include "base/kernel/interfaces/ILineListener.h"
#include "base/net/tools/NetBuffer.h"
#include <cassert>
#include <cstring>
@ -55,7 +56,7 @@ void xmrig::LineReader::reset()
void xmrig::LineReader::add(const char *data, size_t size)
{
if (size > NetBuffer::kChunkSize - m_pos) {
if (size > XMRIG_NET_BUFFER_CHUNK_SIZE - m_pos) {
// it breakes correctness silently for long lines
return;
}

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,10 +20,10 @@
#define XMRIG_MEMPOOL_H
#include <map>
#include <set>
#include <array>
#include <cassert>
#include <map>
#include <set>
namespace xmrig {

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -17,8 +17,9 @@
*/
#include "base/net/tools/MemPool.h"
#include "base/net/tools/NetBuffer.h"
#include "base/kernel/constants.h"
#include "base/net/tools/MemPool.h"
#include <cassert>
@ -28,14 +29,13 @@
namespace xmrig {
static constexpr size_t kInitSize = 4;
static MemPool<NetBuffer::kChunkSize, kInitSize> *pool = nullptr;
static MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS> *pool = nullptr;
inline MemPool<NetBuffer::kChunkSize, kInitSize> *getPool()
inline MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS> *getPool()
{
if (!pool) {
pool = new MemPool<NetBuffer::kChunkSize, kInitSize>();
pool = new MemPool<XMRIG_NET_BUFFER_CHUNK_SIZE, XMRIG_NET_BUFFER_INIT_CHUNKS>();
}
return pool;
@ -67,17 +67,25 @@ void xmrig::NetBuffer::destroy()
void xmrig::NetBuffer::onAlloc(uv_handle_t *, size_t, uv_buf_t *buf)
{
buf->base = getPool()->allocate();
buf->len = kChunkSize;
buf->len = XMRIG_NET_BUFFER_CHUNK_SIZE;
}
void xmrig::NetBuffer::release(const char *buf)
{
if (buf == nullptr) {
return;
}
getPool()->deallocate(buf);
}
void xmrig::NetBuffer::release(const uv_buf_t *buf)
{
if (buf->base == nullptr) {
return;
}
getPool()->deallocate(buf->base);
}

View file

@ -1,6 +1,6 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,8 +33,6 @@ namespace xmrig {
class NetBuffer
{
public:
static constexpr size_t kChunkSize = 16 * 1024;
static char *allocate();
static void destroy();
static void onAlloc(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);