diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 8456d90..aec27ad 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -139,12 +139,6 @@ P2PServer::P2PServer(p2pool* pool) P2PServer::~P2PServer() { - uv_timer_stop(&m_timer); - uv_close(reinterpret_cast(&m_timer), nullptr); - uv_close(reinterpret_cast(&m_broadcastAsync), nullptr); - uv_close(reinterpret_cast(&m_connectToPeersAsync), nullptr); - uv_close(reinterpret_cast(&m_showPeersAsync), nullptr); - shutdown_tcp(); uv_mutex_destroy(&m_rngLock); @@ -1129,6 +1123,15 @@ P2PServer::P2PClient::P2PClient() { } +void P2PServer::on_shutdown() +{ + uv_timer_stop(&m_timer); + uv_close(reinterpret_cast(&m_timer), nullptr); + uv_close(reinterpret_cast(&m_broadcastAsync), nullptr); + uv_close(reinterpret_cast(&m_connectToPeersAsync), nullptr); + uv_close(reinterpret_cast(&m_showPeersAsync), nullptr); +} + P2PServer::P2PClient::~P2PClient() { } diff --git a/src/p2p_server.h b/src/p2p_server.h index 0ad9a7e..3915cfe 100644 --- a/src/p2p_server.h +++ b/src/p2p_server.h @@ -234,6 +234,8 @@ private: static void on_show_peers(uv_async_t* handle) { reinterpret_cast(handle->data)->show_peers(); } void show_peers(); + + void on_shutdown() override; }; } // namespace p2pool diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index f80acaf..9b6c26c 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -84,8 +84,6 @@ StratumServer::StratumServer(p2pool* pool) StratumServer::~StratumServer() { - uv_close(reinterpret_cast(&m_blobsAsync), nullptr); - shutdown_tcp(); uv_mutex_destroy(&m_blobsQueueLock); @@ -935,6 +933,11 @@ void StratumServer::on_after_share_found(uv_work_t* req, int /*status*/) } } +void StratumServer::on_shutdown() +{ + uv_close(reinterpret_cast(&m_blobsAsync), nullptr); +} + StratumServer::StratumClient::StratumClient() : m_rpcId(0) , m_perConnectionJobId(0) diff --git a/src/stratum_server.h b/src/stratum_server.h index 28099c0..d3d0b3c 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -179,6 +179,8 @@ private: void update_hashrate_data(uint64_t hashes, uint64_t timestamp); void api_update_local_stats(uint64_t timestamp); + + void on_shutdown() override; }; } // namespace p2pool diff --git a/src/tcp_server.h b/src/tcp_server.h index eed044b..834f4f2 100644 --- a/src/tcp_server.h +++ b/src/tcp_server.h @@ -181,10 +181,13 @@ protected: uv_async_t m_dropConnectionsAsync; static void on_drop_connections(uv_async_t* async) { reinterpret_cast(async->data)->close_sockets(false); } + virtual void on_shutdown() = 0; + uv_async_t m_shutdownAsync; static void on_shutdown(uv_async_t* async) { TCPServer* server = reinterpret_cast(async->data); + server->on_shutdown(); server->close_sockets(true); uv_close(reinterpret_cast(&server->m_dropConnectionsAsync), nullptr);