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)
{
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);
auto it = m_storage.find(ctx->id());
if (it != m_storage.end()) {
m_storage.erase(it);
for (auto kv : m_storage) {
if (!uv_is_closing(kv.second->handle())) {
uv_close(kv.second->handle(), [](uv_handle_t *handle) -> void { delete reinterpret_cast<HttpContext*>(handle->data); });
}
}
delete ctx;
}

View file

@ -54,9 +54,11 @@ public:
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); }
void close();
static HttpContext *get(uint64_t id);
static void attach(http_parser_settings *settings);
static void close(uv_handle_t* handle);
static void closeAll();
http_parser *parser;
IHttpListener *listener;

View file

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

View file

@ -51,7 +51,7 @@ xmrig::HttpServer::HttpServer(IHttpListener *listener) :
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);
if (parsed < size) {
uv_close(ctx->handle(), HttpContext::close);
ctx->close();
}
} else {
uv_close(ctx->handle(), HttpContext::close);
ctx->close();
}
delete [] buf->base;