Skip to content

Commit 9da4979

Browse files
committed
change reconnect implementation
1 parent 0ad11aa commit 9da4979

File tree

4 files changed

+58
-28
lines changed

4 files changed

+58
-28
lines changed

src/internal/sio_client_impl.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,27 @@ namespace sio
411411

412412
}
413413

414-
void client_impl::reconnect(const std::string& uri)
415-
{
416-
if(m_network_thread)
417-
{
418-
if(m_con_state == con_closing)
419-
{
420-
m_network_thread->join();
421-
}
422-
else
423-
{
424-
return;
425-
}
426-
}
427-
if(m_con_state == con_closed)
428-
{
429-
m_con_state = con_opening;
414+
// void client_impl::reconnect(const std::string& uri)
415+
// {
416+
// if(m_network_thread)
417+
// {
418+
// if(m_con_state == con_closing)
419+
// {
420+
// m_network_thread->join();
421+
// }
422+
// else
423+
// {
424+
// return;
425+
// }
426+
// }
427+
// if(m_con_state == con_closed)
428+
// {
429+
// m_con_state = con_opening;
430430

431-
m_client.get_io_service().dispatch(lib::bind(&client_impl::__connect,this,uri));
432-
m_network_thread.reset(new std::thread(lib::bind(&client_impl::run_loop,this)));//uri
433-
}
434-
}
431+
// m_client.get_io_service().dispatch(lib::bind(&client_impl::__connect,this,uri));
432+
// m_network_thread.reset(new std::thread(lib::bind(&client_impl::run_loop,this)));//uri
433+
// }
434+
// }
435435

436436
socket::ptr const& client_impl::socket(std::string const& nsp)
437437
{

src/internal/sio_client_impl.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void set_##__FIELD__(__TYPE__ const& l) \
8383
// Client Functions - such as send, etc.
8484
void connect(const std::string& uri);
8585

86-
void reconnect(const std::string& uri);
86+
// void reconnect(const std::string& uri);
8787

8888
socket::ptr const& socket(const std::string& nsp);
8989

@@ -95,8 +95,13 @@ void set_##__FIELD__(__TYPE__ const& l) \
9595
bool opened() const { return m_con_state == con_opened; }
9696

9797
std::string const& get_sessionid() const { return m_sid; }
98+
99+
void set_reconnect_attempts(unsigned attempts) {m_reconn_attempts = attempts;}
100+
101+
void set_reconnect_delay(unsigned millis) {m_reconn_delay = millis;if(m_reconn_delay_max<millis) m_reconn_delay_max = millis;}
102+
103+
void set_reconnect_delay_max(unsigned millis) {m_reconn_delay_max = millis;if(m_reconn_delay>millis) m_reconn_delay = millis;}
98104

99-
friend class client;
100105
protected:
101106
void send(packet& p);
102107

@@ -173,6 +178,12 @@ void set_##__FIELD__(__TYPE__ const& l) \
173178
std::map<const std::string,socket::ptr> m_sockets;
174179

175180
std::mutex m_socket_mutex;
181+
182+
unsigned m_reconn_delay;
183+
184+
unsigned m_reconn_delay_max;
185+
186+
unsigned m_reconn_attempts;
176187

177188
friend class sio::client;
178189
friend class sio::socket;

src/sio_client.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ namespace sio
6464
m_impl->connect(uri);
6565
}
6666

67-
void client::reconnect(const std::string& uri)
68-
{
69-
m_impl->reconnect(uri);
70-
}
67+
// void client::reconnect(const std::string& uri)
68+
// {
69+
// m_impl->reconnect(uri);
70+
// }
7171

7272
socket::ptr const& client::socket(const std::string& nsp)
7373
{
@@ -94,5 +94,20 @@ namespace sio
9494
{
9595
return m_impl->get_sessionid();
9696
}
97+
98+
void client::set_reconnect_attempts(int attempts)
99+
{
100+
m_impl->set_reconnect_attempts(attempts);
101+
}
102+
103+
void client::set_reconnect_delay(unsigned millis)
104+
{
105+
m_impl->set_reconnect_delay(millis);
106+
}
107+
108+
void client::set_reconnect_delay_max(unsigned millis)
109+
{
110+
m_impl->set_reconnect_delay_max(millis);
111+
}
97112

98113
}

src/sio_client.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ namespace sio
4949

5050
// Client Functions - such as send, etc.
5151
void connect(const std::string& uri);
52-
53-
void reconnect(const std::string& uri);
52+
53+
void set_reconnect_attempts(int attempts);
54+
55+
void set_reconnect_delay(unsigned millis);
56+
57+
void set_reconnect_delay_max(unsigned millis);
5458

5559
socket::ptr const& socket(const std::string& nsp = "");
5660

0 commit comments

Comments
 (0)