Added workaround, Google Chrome create extra dummy connections for future speed up.

This commit is contained in:
XMRig 2019-03-30 15:51:35 +07:00
parent 106e149324
commit bd6c7c64aa
4 changed files with 25 additions and 14 deletions

View file

@ -67,6 +67,19 @@ xmrig::HttpContext::~HttpContext()
} }
void xmrig::HttpContext::close()
{
auto it = m_storage.find(id());
if (it != m_storage.end()) {
m_storage.erase(it);
}
if (!uv_is_closing(handle())) {
uv_close(handle(), [](uv_handle_t *handle) -> void { delete reinterpret_cast<HttpContext*>(handle->data); });
}
}
xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id) xmrig::HttpContext *xmrig::HttpContext::get(uint64_t id)
{ {
if (m_storage.count(id) == 0) { if (m_storage.count(id) == 0) {
@ -125,15 +138,13 @@ void xmrig::HttpContext::attach(http_parser_settings *settings)
} }
void xmrig::HttpContext::close(uv_handle_t* handle) void xmrig::HttpContext::closeAll()
{ {
HttpContext *ctx = reinterpret_cast<HttpContext*>(handle->data); for (auto kv : m_storage) {
auto it = m_storage.find(ctx->id()); if (!uv_is_closing(kv.second->handle())) {
if (it != m_storage.end()) { uv_close(kv.second->handle(), [](uv_handle_t *handle) -> void { delete reinterpret_cast<HttpContext*>(handle->data); });
m_storage.erase(it); }
} }
delete ctx;
} }

View file

@ -54,9 +54,11 @@ public:
inline uv_stream_t *stream() const { return reinterpret_cast<uv_stream_t *>(tcp); } inline uv_stream_t *stream() const { return reinterpret_cast<uv_stream_t *>(tcp); }
inline uv_handle_t *handle() const { return reinterpret_cast<uv_handle_t *>(tcp); } inline uv_handle_t *handle() const { return reinterpret_cast<uv_handle_t *>(tcp); }
void close();
static HttpContext *get(uint64_t id); static HttpContext *get(uint64_t id);
static void attach(http_parser_settings *settings); static void attach(http_parser_settings *settings);
static void close(uv_handle_t* handle); static void closeAll();
http_parser *parser; http_parser *parser;
IHttpListener *listener; IHttpListener *listener;

View file

@ -103,7 +103,5 @@ void xmrig::HttpResponse::end(const char *data, size_t size)
HttpContext *ctx = HttpContext::get(m_id); HttpContext *ctx = HttpContext::get(m_id);
uv_try_write(ctx->stream(), bufs, data ? 2 : 1); uv_try_write(ctx->stream(), bufs, data ? 2 : 1);
if (!uv_is_closing(ctx->handle())) { ctx->close();
uv_close(ctx->handle(), HttpContext::close);
}
} }

View file

@ -51,7 +51,7 @@ xmrig::HttpServer::HttpServer(IHttpListener *listener) :
xmrig::HttpServer::~HttpServer() xmrig::HttpServer::~HttpServer()
{ {
memset(&http_settings, 0, sizeof (http_settings)); HttpContext::closeAll();
} }
@ -80,10 +80,10 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
const size_t parsed = http_parser_execute(ctx->parser, &http_settings, buf->base, size); const size_t parsed = http_parser_execute(ctx->parser, &http_settings, buf->base, size);
if (parsed < size) { if (parsed < size) {
uv_close(ctx->handle(), HttpContext::close); ctx->close();
} }
} else { } else {
uv_close(ctx->handle(), HttpContext::close); ctx->close();
} }
delete [] buf->base; delete [] buf->base;