TCPServer: fixed data race during shutdown

This commit is contained in:
SChernykh
2022-10-18 18:41:58 +02:00
parent 0342e7ffb5
commit d081c8ea74
2 changed files with 70 additions and 43 deletions
+5 -11
View File
@@ -163,7 +163,6 @@ protected:
int m_listenPort;
uv_loop_t m_loop;
std::atomic<bool> m_loopStopped;
uv_mutex_t m_clientsListLock;
std::vector<Client*> m_preallocatedClients;
@@ -184,17 +183,12 @@ protected:
virtual void on_shutdown() = 0;
uv_async_t m_shutdownAsync;
static void on_shutdown(uv_async_t* async)
{
TCPServer* server = reinterpret_cast<TCPServer*>(async->data);
server->on_shutdown();
server->close_sockets(true);
uv_prepare_t m_shutdownPrepare;
uv_timer_t m_shutdownTimer;
uint32_t m_shutdownCountdown;
uint32_t m_numHandles;
uv_close(reinterpret_cast<uv_handle_t*>(&server->m_dropConnectionsAsync), nullptr);
uv_close(reinterpret_cast<uv_handle_t*>(&server->m_shutdownAsync), nullptr);
delete GetLoopUserData(&server->m_loop, false);
}
static void on_shutdown(uv_async_t* async);
};
} // namespace p2pool