diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index f9c56e05..ab493585 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -79,7 +79,8 @@ static const char *states[] = { xmrig::Client::Client(int id, const char *agent, IClientListener *listener) : BaseClient(id, listener), - m_agent(agent) + m_agent(agent), + m_sendBuf(1024) { m_key = m_storage.add(this); m_dns = new Dns(this); @@ -158,13 +159,11 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) obj.Accept(writer); const size_t size = buffer.GetSize(); - if (size > (sizeof(m_sendBuf) - 2)) { - LOG_ERR("[%s] send failed: \"send buffer overflow: %zu > %zu\"", url(), size, (sizeof(m_sendBuf) - 2)); - close(); - return -1; + if (size > (m_sendBuf.size() - 2)) { + m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024); } - memcpy(m_sendBuf, buffer.GetString(), size); + memcpy(m_sendBuf.data(), buffer.GetString(), size); m_sendBuf[size] = '\n'; m_sendBuf[size + 1] = '\0'; @@ -186,8 +185,8 @@ int64_t xmrig::Client::submit(const JobResult &result) const char *nonce = result.nonce; const char *data = result.result; # else - char *nonce = m_sendBuf; - char *data = m_sendBuf + 16; + char *nonce = m_sendBuf.data(); + char *data = m_sendBuf.data() + 16; Buffer::toHex(reinterpret_cast(&result.nonce), 4, nonce); nonce[8] = '\0'; @@ -529,11 +528,11 @@ int xmrig::Client::resolve(const String &host) int64_t xmrig::Client::send(size_t size) { - LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf); + LOG_DEBUG("[%s] send (%d bytes): \"%.*s\"", url(), size, static_cast(size) - 1, m_sendBuf.data()); # ifdef XMRIG_FEATURE_TLS if (isTLS()) { - if (!m_tls->send(m_sendBuf, size)) { + if (!m_tls->send(m_sendBuf.data(), size)) { return -1; } } @@ -545,7 +544,7 @@ int64_t xmrig::Client::send(size_t size) return -1; } - uv_buf_t buf = uv_buf_init(m_sendBuf, (unsigned int) size); + uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size); if (uv_try_write(m_stream, &buf, 1) < 0) { close(); @@ -795,7 +794,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co void xmrig::Client::ping() { - send(snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); + send(snprintf(m_sendBuf.data(), m_sendBuf.size(), "{\"id\":%" PRId64 ",\"jsonrpc\":\"2.0\",\"method\":\"keepalived\",\"params\":{\"id\":\"%s\"}}\n", m_sequence, m_rpcId.data())); m_keepAlive = 0; } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index fbf594a5..4db21219 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -128,11 +128,11 @@ private: static inline Client *getClient(void *data) { return m_storage.get(data); } - char m_sendBuf[4096] = { 0 }; const char *m_agent; Dns *m_dns; RecvBuf m_recvBuf; std::bitset m_extensions; + std::vector m_sendBuf; String m_rpcId; Tls *m_tls = nullptr; uint64_t m_expire = 0;