diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index 0ff9bf7b2a..a1024fb28c 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -152,12 +152,9 @@ cluster::cluster(const std::string &_token, uint32_t _intents, uint32_t _shards, cluster::~cluster() { - this->shutdown(); delete rest; delete raw_rest; -#ifdef _WIN32 - WSACleanup(); -#endif + this->shutdown(); } request_queue* cluster::get_rest() { @@ -315,7 +312,6 @@ void cluster::shutdown() { terminating = true; { std::lock_guard l(timer_guard); - log(ll_info, "Terminating " + std::to_string(timer_list.size()) + "timers"); /* Free memory for active timers */ for (auto &t: timer_list) { delete t.second; @@ -325,13 +321,12 @@ void cluster::shutdown() { } /* Terminate shards */ for (const auto& sh : shards) { - log(ll_info, "Terminating shard id " + std::to_string(sh.second->shard_id)); delete sh.second; } + shards.clear(); if (engine_thread) { engine_thread->join(); } - shards.clear(); } snowflake cluster::get_dm_channel(snowflake user_id) { diff --git a/src/dpp/socketengines/poll.cpp b/src/dpp/socketengines/poll.cpp index 197fdf6640..148e01a716 100644 --- a/src/dpp/socketengines/poll.cpp +++ b/src/dpp/socketengines/poll.cpp @@ -108,6 +108,12 @@ struct socket_engine_poll : public socket_engine_base { prune(); } +#if _WIN32 + ~socket_engine_poll() override { + WSACleanup(); + } +#endif + bool register_socket(const socket_events& e) final { bool r = socket_engine_base::register_socket(e); if (r) { diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index 24ff575aca..a185e7b4b1 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -501,24 +501,26 @@ void ssl_client::read_loop() owner->socketengine->register_socket(events); }; setup_events(); - timer_handle = owner->start_timer([this, setup_events](auto handle) { - one_second_timer(); - if (!tcp_connect_done && time(nullptr) > start + 2 && connect_retries < 3) { - /* Retry failed connect(). This can happen even in the best situation with bullet-proof hosting. - * Previously with blocking connect() there was some leniency in this, but now we have to do this - * ourselves. - * - * Retry up to 3 times, 2 seconds between retries. After this, give up and let timeout code - * take the wheel (will likely end with an exception). - */ - close_socket(sfd); - owner->socketengine->delete_socket(sfd); - ssl_client::connect(); - setup_events(); - start = time(nullptr) + 2; - connect_retries++; - } - }, 1); + if (!timer_handle) { + timer_handle = owner->start_timer([this, setup_events](auto handle) { + one_second_timer(); + if (!tcp_connect_done && time(nullptr) > start + 2 && connect_retries < 3) { + /* Retry failed connect(). This can happen even in the best situation with bullet-proof hosting. + * Previously with blocking connect() there was some leniency in this, but now we have to do this + * ourselves. + * + * Retry up to 3 times, 2 seconds between retries. After this, give up and let timeout code + * take the wheel (will likely end with an exception). + */ + close_socket(sfd); + owner->socketengine->delete_socket(sfd); + ssl_client::connect(); + setup_events(); + start = time(nullptr) + 2; + connect_retries++; + } + }, 1); + } } uint64_t ssl_client::get_bytes_out()