mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-08 20:09:52 +00:00
#478 Fixed totally broken reconnect.
This commit is contained in:
parent
f852996f97
commit
6f4ed5f66d
4 changed files with 44 additions and 16 deletions
|
@ -6,6 +6,10 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
add_definitions(/DNDEBUG)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing")
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
*
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -36,6 +36,8 @@
|
|||
|
||||
void App::background()
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
if (m_options->affinity() != -1L) {
|
||||
Cpu::setAffinity(-1, m_options->affinity());
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <iterator>
|
||||
#include <stdio.h>
|
||||
|
@ -204,16 +205,30 @@ bool Client::close()
|
|||
|
||||
setState(ClosingState);
|
||||
|
||||
uv_read_stop(reinterpret_cast<uv_stream_t*>(m_socket));
|
||||
uv_stream_t *stream = reinterpret_cast<uv_stream_t*>(m_socket);
|
||||
|
||||
uv_shutdown(new uv_shutdown_t, reinterpret_cast<uv_stream_t*>(m_socket), [](uv_shutdown_t* req, int status) {
|
||||
if (uv_is_readable(stream) == 1) {
|
||||
uv_read_stop(stream);
|
||||
}
|
||||
|
||||
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(req->handle)) == 0) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(req->handle), Client::onClose);
|
||||
if (uv_is_writable(stream) == 1) {
|
||||
const int rc = uv_shutdown(new uv_shutdown_t, stream, [](uv_shutdown_t* req, int status) {
|
||||
if (uv_is_closing(reinterpret_cast<uv_handle_t*>(req->handle)) == 0) {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(req->handle), Client::onClose);
|
||||
}
|
||||
|
||||
delete req;
|
||||
});
|
||||
|
||||
assert(rc == 0);
|
||||
|
||||
if (rc != 0) {
|
||||
onClose();
|
||||
}
|
||||
|
||||
delete req;
|
||||
});
|
||||
}
|
||||
else {
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(m_socket), Client::onClose);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -442,6 +457,18 @@ void Client::login()
|
|||
}
|
||||
|
||||
|
||||
void Client::onClose()
|
||||
{
|
||||
delete m_socket;
|
||||
|
||||
m_stream = nullptr;
|
||||
m_socket = nullptr;
|
||||
setState(UnconnectedState);
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
|
||||
void Client::parse(char *line, size_t len)
|
||||
{
|
||||
startTimeout();
|
||||
|
@ -655,13 +682,7 @@ void Client::onClose(uv_handle_t *handle)
|
|||
return;
|
||||
}
|
||||
|
||||
delete client->m_socket;
|
||||
|
||||
client->m_stream = nullptr;
|
||||
client->m_socket = nullptr;
|
||||
client->setState(UnconnectedState);
|
||||
|
||||
client->reconnect();
|
||||
client->onClose();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
|
||||
void connect(sockaddr *addr);
|
||||
void login();
|
||||
void onClose();
|
||||
void parse(char *line, size_t len);
|
||||
void parseExtensions(const rapidjson::Value &value);
|
||||
void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error);
|
||||
|
|
Loading…
Reference in a new issue