From 98cfe7ed37ad8f290983f164d91f41ce565b6285 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 23:44:32 +0700 Subject: [PATCH] Added extra error message. --- src/base/net/stratum/Client.cpp | 26 +++++++++++++++++++------- src/base/net/stratum/Client.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index a995bef3..30ef20ea 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -466,11 +466,7 @@ bool xmrig::Client::send(BIO *bio) bool result = false; if (state() == ConnectedState && uv_is_writable(m_stream)) { - result = uv_try_write(m_stream, &buf, 1) > 0; - - if (!result) { - close(); - } + result = write(buf); } else { LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state); @@ -511,6 +507,23 @@ bool xmrig::Client::verifyAlgorithm(const Algorithm &algorithm, const char *algo } +bool xmrig::Client::write(const uv_buf_t &buf) +{ + const int rc = uv_try_write(m_stream, &buf, 1); + if (static_cast(rc) == buf.len) { + return true; + } + + if (!isQuiet()) { + LOG_ERR("[%s] write error: \"%s\"", url(), uv_strerror(rc)); + } + + close(); + + return false; +} + + int xmrig::Client::resolve(const String &host) { setState(HostLookupState); @@ -553,8 +566,7 @@ int64_t xmrig::Client::send(size_t size) uv_buf_t buf = uv_buf_init(m_sendBuf.data(), (unsigned int) size); - if (uv_try_write(m_stream, &buf, 1) < 0) { - close(); + if (!write(buf)) { return -1; } } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 1949e61f..ec90dd85 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -96,6 +96,7 @@ private: bool parseLogin(const rapidjson::Value &result, int *code); bool send(BIO *bio); bool verifyAlgorithm(const Algorithm &algorithm, const char *algo) const; + bool write(const uv_buf_t &buf); int resolve(const String &host); int64_t send(size_t size); void connect(sockaddr *addr);