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)
|
// void client_impl::reconnect(const std::string& uri)
|
||||||
{
|
// {
|
||||||
if(m_network_thread)
|
// if(m_network_thread)
|
||||||
{
|
// {
|
||||||
if(m_con_state == con_closing)
|
// if(m_con_state == con_closing)
|
||||||
{
|
// {
|
||||||
m_network_thread->join();
|
// m_network_thread->join();
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if(m_con_state == con_closed)
|
// if(m_con_state == con_closed)
|
||||||
{
|
// {
|
||||||
m_con_state = con_opening;
|
// m_con_state = con_opening;
|
||||||
|
|
||||||
m_client.get_io_service().dispatch(lib::bind(&client_impl::__connect,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
|
// 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)
|
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.
|
// Client Functions - such as send, etc.
|
||||||
void connect(const std::string& uri);
|
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);
|
socket::ptr const& socket(const std::string& nsp);
|
||||||
|
|
||||||
@ -95,8 +95,13 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
|||||||
bool opened() const { return m_con_state == con_opened; }
|
bool opened() const { return m_con_state == con_opened; }
|
||||||
|
|
||||||
std::string const& get_sessionid() const { return m_sid; }
|
std::string const& get_sessionid() const { return m_sid; }
|
||||||
|
|
||||||
|
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;}
|
||||||
|
|
||||||
friend class client;
|
|
||||||
protected:
|
protected:
|
||||||
void send(packet& p);
|
void send(packet& p);
|
||||||
|
|
||||||
@ -173,6 +178,12 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
|||||||
std::map<const std::string,socket::ptr> m_sockets;
|
std::map<const std::string,socket::ptr> m_sockets;
|
||||||
|
|
||||||
std::mutex m_socket_mutex;
|
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::client;
|
||||||
friend class sio::socket;
|
friend class sio::socket;
|
||||||
|
|||||||
@ -64,10 +64,10 @@ namespace sio
|
|||||||
m_impl->connect(uri);
|
m_impl->connect(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
void client::reconnect(const std::string& uri)
|
// void client::reconnect(const std::string& uri)
|
||||||
{
|
// {
|
||||||
m_impl->reconnect(uri);
|
// m_impl->reconnect(uri);
|
||||||
}
|
// }
|
||||||
|
|
||||||
socket::ptr const& client::socket(const std::string& nsp)
|
socket::ptr const& client::socket(const std::string& nsp)
|
||||||
{
|
{
|
||||||
@ -94,5 +94,20 @@ namespace sio
|
|||||||
{
|
{
|
||||||
return m_impl->get_sessionid();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,8 +49,12 @@ namespace sio
|
|||||||
|
|
||||||
// Client Functions - such as send, etc.
|
// Client Functions - such as send, etc.
|
||||||
void connect(const std::string& uri);
|
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 = "");
|
socket::ptr const& socket(const std::string& nsp = "");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user