From 0c1f08b87760b2ffe7f48f2681b31da0975a24df Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 Apr 2023 11:15:00 +0800 Subject: [PATCH] 1 --- server/wsproxy/downstream.cc | 2 +- server/wsproxy/downstream.h | 7 +++++-- server/wsproxy/downstreammgr.cc | 18 +++++++++--------- server/wsproxy/upstreammgr.cc | 6 +++--- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/server/wsproxy/downstream.cc b/server/wsproxy/downstream.cc index f59dc5a..3677608 100644 --- a/server/wsproxy/downstream.cc +++ b/server/wsproxy/downstream.cc @@ -14,6 +14,6 @@ void DownStream::OnClose() { if (!GetUpStream().expired()) { ss::SS_WSP_SocketDisconnect msg; - GetUpStream().lock()->SendMsg(socket_handle, msg); + GetUpStream().lock()->SendMsg(socket_handle_, msg); } } diff --git a/server/wsproxy/downstream.h b/server/wsproxy/downstream.h index 720208b..c25697b 100644 --- a/server/wsproxy/downstream.h +++ b/server/wsproxy/downstream.h @@ -4,14 +4,17 @@ class UpStream; class DownStream { public: - int socket_handle = a8::INVALID_SOCKET_HANDLE; - void SetUpStream(std::weak_ptr up) { up_ = up; } + int GetSocketHandle() { return socket_handle_; } + void SetSocketHandle(int socket_handle) { socket_handle_ = socket_handle; } std::weak_ptr GetUpStream() { return up_; } + void SetUpStream(std::weak_ptr up) { up_ = up; } + void ForwardUpStreamMsg(f8::MsgHdr& hdr); void OnClose(); private: + int socket_handle_ = a8::INVALID_SOCKET_HANDLE; int type_ = 0; std::weak_ptr up_; }; diff --git a/server/wsproxy/downstreammgr.cc b/server/wsproxy/downstreammgr.cc index 374624d..35f0942 100644 --- a/server/wsproxy/downstreammgr.cc +++ b/server/wsproxy/downstreammgr.cc @@ -60,9 +60,9 @@ void DownStreamMgr::OnUpStreamDisconnect(int instance_id) } } for (auto& client : delete_client) { - RemovePendingAccount(client->socket_handle); - GCListener::Instance()->ForceCloseClient(client->socket_handle); - socket_hash_.erase(client->socket_handle); + RemovePendingAccount(client->GetSocketHandle()); + GCListener::Instance()->ForceCloseClient(client->GetSocketHandle()); + socket_hash_.erase(client->GetSocketHandle()); } } @@ -79,16 +79,16 @@ std::weak_ptr DownStreamMgr::GetDownStream(int sockhandle) void DownStreamMgr::BindUpStream(int socket_handle, int conn_instance_id) { - std::weak_ptr conn = UpStreamMgr::Instance()->GetUpStreamById(conn_instance_id); - if (!conn.expired()) { + std::weak_ptr up_wp = UpStreamMgr::Instance()->GetUpStreamById(conn_instance_id); + if (!up_wp.expired()) { auto down_wp = GetDownStream(socket_handle); if (auto down = down_wp.lock(); !down_wp.expired()) { - down->SetUpStream(conn); + down->SetUpStream(up_wp); } else { down = std::make_shared(); - down->socket_handle = socket_handle; - down->SetUpStream(conn); - socket_hash_[down->socket_handle] = down; + down->SetSocketHandle(socket_handle); + down->SetUpStream(up_wp); + socket_hash_[down->GetSocketHandle()] = down; f8::UdpLog::Instance()->Info("BindUpStream socket_handle:%d", { socket_handle diff --git a/server/wsproxy/upstreammgr.cc b/server/wsproxy/upstreammgr.cc index 86b7c74..93e120c 100644 --- a/server/wsproxy/upstreammgr.cc +++ b/server/wsproxy/upstreammgr.cc @@ -15,9 +15,9 @@ void UpStreamMgr::Init() [this] (const a8::Args& args) { int instance_id = args.Get(0); - std::weak_ptr conn = GetUpStreamById(instance_id); - if (!conn.expired() && conn.lock()->Connected()) { - conn.lock()->SendStockMsg(); + std::weak_ptr up_wp = GetUpStreamById(instance_id); + if (!up_wp.expired() && up_wp.lock()->Connected()) { + up_wp.lock()->SendStockMsg(); } }); f8::MsgQueue::Instance()->RegisterCallBack