Skip to content

Commit bacd917

Browse files
authored
core: abort retrying when closing down. (#312)
Signed-off-by: Patti Vacek <[email protected]>
1 parent 5a0c1ec commit bacd917

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/internal/sio_client_impl.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace sio
111111
m_auth = auth;
112112

113113
this->reset_states();
114+
m_abort_retries = false;
114115
m_client.get_io_service().dispatch(std::bind(&client_impl::connect_impl,this,uri,m_query_string));
115116
m_network_thread.reset(new thread(std::bind(&client_impl::run_loop,this)));//uri lifecycle?
116117

@@ -149,13 +150,15 @@ namespace sio
149150
void client_impl::close()
150151
{
151152
m_con_state = con_closing;
153+
m_abort_retries = true;
152154
this->sockets_invoke_void(&sio::socket::close);
153155
m_client.get_io_service().dispatch(std::bind(&client_impl::close_impl, this,close::status::normal,"End by user"));
154156
}
155157

156158
void client_impl::sync_close()
157159
{
158160
m_con_state = con_closing;
161+
m_abort_retries = true;
159162
this->sockets_invoke_void(&sio::socket::close);
160163
m_client.get_io_service().dispatch(std::bind(&client_impl::close_impl, this,close::status::normal,"End by user"));
161164
if(m_network_thread)
@@ -375,7 +378,7 @@ namespace sio
375378
m_con_state = con_closed;
376379
this->sockets_invoke_void(&sio::socket::on_disconnect);
377380
LOG("Connection failed." << endl);
378-
if(m_reconn_made<m_reconn_attempts)
381+
if(m_reconn_made<m_reconn_attempts && !m_abort_retries)
379382
{
380383
LOG("Reconnect for attempt:"<<m_reconn_made<<endl);
381384
unsigned delay = this->next_delay();
@@ -439,7 +442,7 @@ namespace sio
439442
else
440443
{
441444
this->sockets_invoke_void(&sio::socket::on_disconnect);
442-
if(m_reconn_made<m_reconn_attempts)
445+
if(m_reconn_made<m_reconn_attempts && !m_abort_retries)
443446
{
444447
LOG("Reconnect for attempt:"<<m_reconn_made<<endl);
445448
unsigned delay = this->next_delay();

src/internal/sio_client_impl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef websocketpp::config::asio_client client_config;
3838
#include <asio/error_code.hpp>
3939
#include <asio/io_service.hpp>
4040

41+
#include <atomic>
4142
#include <memory>
4243
#include <map>
4344
#include <thread>
@@ -236,7 +237,9 @@ namespace sio
236237
unsigned m_reconn_attempts;
237238

238239
unsigned m_reconn_made;
239-
240+
241+
std::atomic<bool> m_abort_retries { false };
242+
240243
friend class sio::client;
241244
friend class sio::socket;
242245
};

0 commit comments

Comments
 (0)