core: abort retrying when closing down. (#312)

Signed-off-by: Patti Vacek <pattivacek@gmail.com>
This commit is contained in:
Patti Vacek 2022-03-29 10:00:34 +02:00 committed by GitHub
parent 5a0c1ececd
commit bacd9172e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -111,6 +111,7 @@ namespace sio
m_auth = auth;
this->reset_states();
m_abort_retries = false;
m_client.get_io_service().dispatch(std::bind(&client_impl::connect_impl,this,uri,m_query_string));
m_network_thread.reset(new thread(std::bind(&client_impl::run_loop,this)));//uri lifecycle?
@ -149,6 +150,7 @@ namespace sio
void client_impl::close()
{
m_con_state = con_closing;
m_abort_retries = true;
this->sockets_invoke_void(&sio::socket::close);
m_client.get_io_service().dispatch(std::bind(&client_impl::close_impl, this,close::status::normal,"End by user"));
}
@ -156,6 +158,7 @@ namespace sio
void client_impl::sync_close()
{
m_con_state = con_closing;
m_abort_retries = true;
this->sockets_invoke_void(&sio::socket::close);
m_client.get_io_service().dispatch(std::bind(&client_impl::close_impl, this,close::status::normal,"End by user"));
if(m_network_thread)
@ -375,7 +378,7 @@ namespace sio
m_con_state = con_closed;
this->sockets_invoke_void(&sio::socket::on_disconnect);
LOG("Connection failed." << endl);
if(m_reconn_made<m_reconn_attempts)
if(m_reconn_made<m_reconn_attempts && !m_abort_retries)
{
LOG("Reconnect for attempt:"<<m_reconn_made<<endl);
unsigned delay = this->next_delay();
@ -439,7 +442,7 @@ namespace sio
else
{
this->sockets_invoke_void(&sio::socket::on_disconnect);
if(m_reconn_made<m_reconn_attempts)
if(m_reconn_made<m_reconn_attempts && !m_abort_retries)
{
LOG("Reconnect for attempt:"<<m_reconn_made<<endl);
unsigned delay = this->next_delay();

View File

@ -38,6 +38,7 @@ typedef websocketpp::config::asio_client client_config;
#include <asio/error_code.hpp>
#include <asio/io_service.hpp>
#include <atomic>
#include <memory>
#include <map>
#include <thread>
@ -236,7 +237,9 @@ namespace sio
unsigned m_reconn_attempts;
unsigned m_reconn_made;
std::atomic<bool> m_abort_retries { false };
friend class sio::client;
friend class sio::socket;
};