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

@ -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);
}