mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 00:37:46 +00:00
Code cleanup.
This commit is contained in:
parent
4dddd3a44f
commit
914b7023a2
3 changed files with 12 additions and 18 deletions
|
@ -52,7 +52,7 @@ public:
|
|||
m_ctx(ctx),
|
||||
m_body(std::move(body))
|
||||
{
|
||||
m_buf = uv_buf_init(const_cast<char *>(m_body.c_str()), m_body.size());
|
||||
m_buf = uv_buf_init(&m_body.front(), m_body.size());
|
||||
}
|
||||
|
||||
inline ~HttpWriteBaton()
|
||||
|
|
|
@ -155,8 +155,6 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj)
|
|||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
Value value;
|
||||
|
||||
StringBuffer buffer(nullptr, 512);
|
||||
Writer<StringBuffer> writer(buffer);
|
||||
obj.Accept(writer);
|
||||
|
@ -481,7 +479,7 @@ bool xmrig::Client::send(BIO *bio)
|
|||
LOG_DEBUG("[%s] TLS send (%d bytes)", url(), static_cast<int>(buf.len));
|
||||
|
||||
bool result = false;
|
||||
if (state() == ConnectedState && uv_is_writable(m_stream)) {
|
||||
if (state() == ConnectedState && uv_is_writable(stream())) {
|
||||
result = write(buf);
|
||||
}
|
||||
else {
|
||||
|
@ -525,7 +523,7 @@ 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);
|
||||
const int rc = uv_try_write(stream(), &buf, 1);
|
||||
if (static_cast<size_t>(rc) == buf.len) {
|
||||
return true;
|
||||
}
|
||||
|
@ -575,7 +573,7 @@ int64_t xmrig::Client::send(size_t size)
|
|||
else
|
||||
# endif
|
||||
{
|
||||
if (state() != ConnectedState || !uv_is_writable(m_stream)) {
|
||||
if (state() != ConnectedState || !uv_is_writable(stream())) {
|
||||
LOG_DEBUG_ERR("[%s] send failed, invalid state: %d", url(), m_state);
|
||||
return -1;
|
||||
}
|
||||
|
@ -664,7 +662,6 @@ void xmrig::Client::onClose()
|
|||
{
|
||||
delete m_socket;
|
||||
|
||||
m_stream = nullptr;
|
||||
m_socket = nullptr;
|
||||
setState(UnconnectedState);
|
||||
|
||||
|
@ -966,8 +963,9 @@ void xmrig::Client::onClose(uv_handle_t *handle)
|
|||
void xmrig::Client::onConnect(uv_connect_t *req, int status)
|
||||
{
|
||||
auto client = getClient(req->data);
|
||||
delete req;
|
||||
|
||||
if (!client) {
|
||||
delete req;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -988,7 +986,6 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
|
|||
return;
|
||||
}
|
||||
|
||||
delete req;
|
||||
client->close();
|
||||
return;
|
||||
}
|
||||
|
@ -999,12 +996,9 @@ void xmrig::Client::onConnect(uv_connect_t *req, int status)
|
|||
return;
|
||||
}
|
||||
|
||||
client->m_stream = static_cast<uv_stream_t*>(req->handle);
|
||||
client->m_stream->data = req->data;
|
||||
client->setState(ConnectedState);
|
||||
|
||||
uv_read_start(client->m_stream, NetBuffer::onAlloc, onRead);
|
||||
delete req;
|
||||
uv_read_start(client->stream(), NetBuffer::onAlloc, onRead);
|
||||
|
||||
client->handshake();
|
||||
}
|
||||
|
|
|
@ -112,10 +112,11 @@ private:
|
|||
void setState(SocketState state);
|
||||
void startTimeout();
|
||||
|
||||
inline const char *url() const { return m_pool.url(); }
|
||||
inline SocketState state() const { return m_state; }
|
||||
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
inline const char *url() const { return m_pool.url(); }
|
||||
inline SocketState state() const { return m_state; }
|
||||
inline uv_stream_t *stream() const { return reinterpret_cast<uv_stream_t *>(m_socket); }
|
||||
inline void setExtension(Extension ext, bool enable) noexcept { m_extensions.set(ext, enable); }
|
||||
template<Extension ext> inline bool has() const noexcept { return m_extensions.test(ext); }
|
||||
|
||||
static void onClose(uv_handle_t *handle);
|
||||
static void onConnect(uv_connect_t *req, int status);
|
||||
|
@ -135,7 +136,6 @@ private:
|
|||
uint64_t m_jobs = 0;
|
||||
uint64_t m_keepAlive = 0;
|
||||
uintptr_t m_key = 0;
|
||||
uv_stream_t *m_stream = nullptr;
|
||||
uv_tcp_t *m_socket = nullptr;
|
||||
|
||||
static Storage<Client> m_storage;
|
||||
|
|
Loading…
Reference in a new issue