From 72c9f3b0db91abd6547c56ff0a6d6f94d9ccf528 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 5 Jul 2023 15:29:54 +0200 Subject: [PATCH] Fixed ping time calculation --- src/json_rpc_request.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/json_rpc_request.cpp b/src/json_rpc_request.cpp index 78b4f42..1df0b91 100644 --- a/src/json_rpc_request.cpp +++ b/src/json_rpc_request.cpp @@ -228,7 +228,9 @@ CurlContext::~CurlContext() double tcp_ping = 0.0; if (m_error.empty() && !m_response.empty()) { - tcp_ping = static_cast(m_connectedTime - m_startTime) / 1000.0; + if (m_connectedTime) { + tcp_ping = static_cast(m_connectedTime - m_startTime) / 1000.0; + } (*m_callback)(m_response.data(), m_response.size(), tcp_ping); } delete m_callback; @@ -371,6 +373,10 @@ void CurlContext::on_timeout(uv_handle_t* req) size_t CurlContext::on_write(const void* buffer, size_t size, size_t count) { + if (!m_connectedTime) { + m_connectedTime = microseconds_since_epoch(); + } + const size_t realsize = size * count; const char* p = reinterpret_cast(buffer); m_response.insert(m_response.end(), p, p + realsize);