From f937b70cca53d4cb75fae051595499902541fb6d Mon Sep 17 00:00:00 2001 From: azw Date: Fri, 14 Apr 2023 09:48:24 +0000 Subject: [PATCH] 1 --- server/wsproxy/master.cc | 6 ++++-- server/wsproxy/master.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/wsproxy/master.cc b/server/wsproxy/master.cc index 00435f7..eda3a1b 100644 --- a/server/wsproxy/master.cc +++ b/server/wsproxy/master.cc @@ -24,7 +24,7 @@ void Master::Init(int instance_id, const std::string& remote_ip, int remote_port recv_bufflen_ = 0; last_pong_tick = a8::XGetTickCount(); recv_buff_ = (char*) malloc(PACK_MAX * 2); - tcp_client_ = new a8::TcpClient(); + tcp_client_ = std::make_shared(); tcp_client_->remote_address = remote_ip; tcp_client_->remote_port = remote_port; tcp_client_->on_error = std::bind(&Master::on_error, this, std::placeholders::_1, std::placeholders::_2); @@ -48,7 +48,9 @@ void Master::UnInit() f8::Timer::Instance()->Delete(timer_wp_); } tcp_client_->Close(); - delete tcp_client_; + if (tcp_client_.use_count() != 1) { + abort(); + } tcp_client_ = nullptr; recv_bufflen_ = 0; free(recv_buff_); diff --git a/server/wsproxy/master.h b/server/wsproxy/master.h index 8502cb7..f06cb8b 100644 --- a/server/wsproxy/master.h +++ b/server/wsproxy/master.h @@ -27,7 +27,7 @@ class Master void SendMsg(T& msg) { static int msgid = f8::Net_GetMessageId(msg); - f8::Net_SendMsg(tcp_client_, 0, msgid, msg); + f8::Net_SendMsg(tcp_client_.get(), 0, msgid, msg); } private: @@ -41,7 +41,7 @@ class Master private: char *recv_buff_ = nullptr; unsigned int recv_bufflen_ = 0; - a8::TcpClient* tcp_client_ = nullptr; + std::shared_ptr tcp_client_; f8::TimerWp timer_wp_; f8::Attacher attacher_; };