This commit is contained in:
azw 2023-04-14 09:48:24 +00:00
parent 48a3cd1cdd
commit f937b70cca
2 changed files with 6 additions and 4 deletions

View File

@ -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<a8::TcpClient>();
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_);

View File

@ -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<a8::TcpClient> tcp_client_;
f8::TimerWp timer_wp_;
f8::Attacher attacher_;
};