Reduced memory consumption on network level.

This commit is contained in:
XMRig 2020-03-20 20:53:27 +07:00
parent bb96684daf
commit 1b875fdabb
No known key found for this signature in database
GPG key ID: 446A53638BE94409
17 changed files with 462 additions and 205 deletions

View file

@ -30,9 +30,8 @@
#include "base/net/http/HttpServer.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/net/http/HttpContext.h"
#include "base/net/http/HttpResponse.h"
#include "base/net/tools/NetBuffer.h"
xmrig::HttpServer::HttpServer(const std::shared_ptr<IHttpListener> &listener) :
@ -52,12 +51,7 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
auto ctx = new HttpContext(HTTP_REQUEST, m_listener);
uv_accept(stream, ctx->stream());
uv_read_start(ctx->stream(),
[](uv_handle_t *, size_t suggested_size, uv_buf_t *buf)
{
buf->base = new char[suggested_size];
buf->len = suggested_size;
},
uv_read_start(ctx->stream(), NetBuffer::onAlloc,
[](uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
{
auto ctx = static_cast<HttpContext*>(tcp->data);
@ -73,6 +67,6 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
ctx->close();
}
delete [] buf->base;
NetBuffer::release(buf);
});
}