mirror of
https://github.com/socketio/socket.io-client-cpp.git
synced 2026-06-10 20:36:14 +00:00
change reconnect implementation
This commit is contained in:
parent
0ad11aa607
commit
9da4979d7f
@ -411,27 +411,27 @@ namespace sio
|
||||
|
||||
}
|
||||
|
||||
void client_impl::reconnect(const std::string& uri)
|
||||
{
|
||||
if(m_network_thread)
|
||||
{
|
||||
if(m_con_state == con_closing)
|
||||
{
|
||||
m_network_thread->join();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(m_con_state == con_closed)
|
||||
{
|
||||
m_con_state = con_opening;
|
||||
// void client_impl::reconnect(const std::string& uri)
|
||||
// {
|
||||
// if(m_network_thread)
|
||||
// {
|
||||
// if(m_con_state == con_closing)
|
||||
// {
|
||||
// m_network_thread->join();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// if(m_con_state == con_closed)
|
||||
// {
|
||||
// m_con_state = con_opening;
|
||||
|
||||
m_client.get_io_service().dispatch(lib::bind(&client_impl::__connect,this,uri));
|
||||
m_network_thread.reset(new std::thread(lib::bind(&client_impl::run_loop,this)));//uri
|
||||
}
|
||||
}
|
||||
// m_client.get_io_service().dispatch(lib::bind(&client_impl::__connect,this,uri));
|
||||
// m_network_thread.reset(new std::thread(lib::bind(&client_impl::run_loop,this)));//uri
|
||||
// }
|
||||
// }
|
||||
|
||||
socket::ptr const& client_impl::socket(std::string const& nsp)
|
||||
{
|
||||
|
||||
@ -83,7 +83,7 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
||||
// Client Functions - such as send, etc.
|
||||
void connect(const std::string& uri);
|
||||
|
||||
void reconnect(const std::string& uri);
|
||||
// void reconnect(const std::string& uri);
|
||||
|
||||
socket::ptr const& socket(const std::string& nsp);
|
||||
|
||||
@ -96,7 +96,12 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
||||
|
||||
std::string const& get_sessionid() const { return m_sid; }
|
||||
|
||||
friend class client;
|
||||
void set_reconnect_attempts(unsigned attempts) {m_reconn_attempts = attempts;}
|
||||
|
||||
void set_reconnect_delay(unsigned millis) {m_reconn_delay = millis;if(m_reconn_delay_max<millis) m_reconn_delay_max = millis;}
|
||||
|
||||
void set_reconnect_delay_max(unsigned millis) {m_reconn_delay_max = millis;if(m_reconn_delay>millis) m_reconn_delay = millis;}
|
||||
|
||||
protected:
|
||||
void send(packet& p);
|
||||
|
||||
@ -174,6 +179,12 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
||||
|
||||
std::mutex m_socket_mutex;
|
||||
|
||||
unsigned m_reconn_delay;
|
||||
|
||||
unsigned m_reconn_delay_max;
|
||||
|
||||
unsigned m_reconn_attempts;
|
||||
|
||||
friend class sio::client;
|
||||
friend class sio::socket;
|
||||
};
|
||||
|
||||
@ -64,10 +64,10 @@ namespace sio
|
||||
m_impl->connect(uri);
|
||||
}
|
||||
|
||||
void client::reconnect(const std::string& uri)
|
||||
{
|
||||
m_impl->reconnect(uri);
|
||||
}
|
||||
// void client::reconnect(const std::string& uri)
|
||||
// {
|
||||
// m_impl->reconnect(uri);
|
||||
// }
|
||||
|
||||
socket::ptr const& client::socket(const std::string& nsp)
|
||||
{
|
||||
@ -95,4 +95,19 @@ namespace sio
|
||||
return m_impl->get_sessionid();
|
||||
}
|
||||
|
||||
void client::set_reconnect_attempts(int attempts)
|
||||
{
|
||||
m_impl->set_reconnect_attempts(attempts);
|
||||
}
|
||||
|
||||
void client::set_reconnect_delay(unsigned millis)
|
||||
{
|
||||
m_impl->set_reconnect_delay(millis);
|
||||
}
|
||||
|
||||
void client::set_reconnect_delay_max(unsigned millis)
|
||||
{
|
||||
m_impl->set_reconnect_delay_max(millis);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,7 +50,11 @@ namespace sio
|
||||
// Client Functions - such as send, etc.
|
||||
void connect(const std::string& uri);
|
||||
|
||||
void reconnect(const std::string& uri);
|
||||
void set_reconnect_attempts(int attempts);
|
||||
|
||||
void set_reconnect_delay(unsigned millis);
|
||||
|
||||
void set_reconnect_delay_max(unsigned millis);
|
||||
|
||||
socket::ptr const& socket(const std::string& nsp = "");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user