mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
1.Use std::move to initialize std::thread; 2.Fix thread cannot exit error
This commit is contained in:
@@ -13,8 +13,8 @@ WsCore::WsCore() {
|
||||
m_endpoint_.init_asio();
|
||||
m_endpoint_.start_perpetual();
|
||||
|
||||
m_thread_ = websocketpp::lib::make_shared<websocketpp::lib::thread>(
|
||||
&client::run, &m_endpoint_);
|
||||
std::thread t(&client::run, &m_endpoint_);
|
||||
m_thread_ = std::move(t);
|
||||
}
|
||||
|
||||
WsCore::~WsCore() {
|
||||
@@ -32,12 +32,12 @@ WsCore::~WsCore() {
|
||||
LOG_INFO("Closing connection error: {}", ec.message());
|
||||
}
|
||||
|
||||
if (m_thread_->joinable()) {
|
||||
m_thread_->join();
|
||||
if (m_thread_.joinable()) {
|
||||
m_thread_.join();
|
||||
}
|
||||
|
||||
if (ping_thread_->joinable()) {
|
||||
ping_thread_->join();
|
||||
if (ping_thread_.joinable()) {
|
||||
ping_thread_.join();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,8 +129,8 @@ void WsCore::OnOpen(client *c, websocketpp::connection_hdl hdl) {
|
||||
ws_status_ = WsStatus::WsOpened;
|
||||
OnWsStatus(WsStatus::WsOpened);
|
||||
|
||||
ping_thread_ = websocketpp::lib::make_shared<websocketpp::lib::thread>(
|
||||
&WsCore::Ping, this, hdl);
|
||||
std::thread t(&WsCore::Ping, this, hdl);
|
||||
ping_thread_ = std::move(t);
|
||||
}
|
||||
|
||||
void WsCore::OnFail(client *c, websocketpp::connection_hdl hdl) {
|
||||
|
||||
@@ -53,8 +53,8 @@ class WsCore {
|
||||
private:
|
||||
client m_endpoint_;
|
||||
websocketpp::connection_hdl connection_handle_;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread_;
|
||||
websocketpp::lib::shared_ptr<websocketpp::lib::thread> ping_thread_;
|
||||
std::thread m_thread_;
|
||||
std::thread ping_thread_;
|
||||
|
||||
WsStatus ws_status_ = WsStatus::WsClosed;
|
||||
int timeout_count_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user