From 71175471e19c3ff5871ba9a55c923af8a491657a Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 9 Apr 2023 08:59:03 +0000 Subject: [PATCH] 1 --- server/wsproxy/downstreammgr.cc | 47 +++++++++++++++++---------------- server/wsproxy/downstreammgr.h | 6 ++--- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/server/wsproxy/downstreammgr.cc b/server/wsproxy/downstreammgr.cc index b5ae978..dd3d4a7 100644 --- a/server/wsproxy/downstreammgr.cc +++ b/server/wsproxy/downstreammgr.cc @@ -12,6 +12,14 @@ #include "GCListener.h" #include "app.h" +struct PendingAccount +{ + int socket_handle = 0; + std::string account_id; + long long add_tick = 0; + f8::TimerWp timer_wp; +}; + void DownStreamMgr::Init() { f8::MsgQueue::Instance()->RegisterCallBack @@ -27,9 +35,7 @@ void DownStreamMgr::Init() void DownStreamMgr::UnInit() { socket_hash_.clear(); - #if 0 pending_account_hash_.clear(); - #endif } void DownStreamMgr::OnClientDisconnect(int socket_handle) @@ -90,26 +96,17 @@ void DownStreamMgr::BindUpStream(int socket_handle, int conn_instance_id) socket_hash_[down->socket_handle] = down; f8::UdpLog::Instance()->Info("BindUpStream socket_handle:%d", {socket_handle}); { - #if 0 - auto itr = pending_account_hash_.find(socket_handle); - if (itr != pending_account_hash_.end()) { - std::string account_id = std::get<0>(itr->second); - long long req_tick = std::get<1>(itr->second); + if (auto pending_account = GetPendingAccount(socket_handle)) { long long cur_tick = a8::XGetTickCount(); - if (cur_tick - req_tick > App::Instance()->perf.max_join_time) { - App::Instance()->perf.max_join_time = cur_tick - req_tick; + if (cur_tick - pending_account->add_tick > App::Instance()->perf.max_join_time) { + App::Instance()->perf.max_join_time = cur_tick - pending_account->add_tick; } - if (account_id == azw_account_id) { - f8::UdpLog::Instance()->Info("%s join time:%d", - { - account_id, - cur_tick - req_tick - }); - } - f8::UdpLog::Instance()->Info("BindUpStream account_id:%s", {account_id}); + f8::UdpLog::Instance()->Info("BindUpStream account_id:%s", + { + pending_account->account_id + }); RemovePendingAccount(socket_handle); } - #endif } } } @@ -141,16 +138,20 @@ void DownStreamMgr::AddPendingAccount(const std::string& account_id, int socket_ #endif } +std::shared_ptr DownStreamMgr::GetPendingAccount(int socket_handle) +{ + auto itr = pending_account_hash_.find(socket_handle); + return itr != pending_account_hash_.end() ? itr->second : nullptr; +} + void DownStreamMgr::RemovePendingAccount(int socket_handle) { - #if 0 f8::UdpLog::Instance()->Info("RemovePendingAccount %d", {socket_handle}); auto itr = pending_account_hash_.find(socket_handle); if (itr != pending_account_hash_.end()) { - #if 0 - f8::Timer::Instance()->DeleteTimer(std::get<2>(itr->second)); + if (!itr->second->timer_wp.expired()) { + f8::Timer::Instance()->Delete(itr->second->timer_wp); + } pending_account_hash_.erase(itr); - #endif } - #endif } diff --git a/server/wsproxy/downstreammgr.h b/server/wsproxy/downstreammgr.h index 94f3b46..80110b9 100644 --- a/server/wsproxy/downstreammgr.h +++ b/server/wsproxy/downstreammgr.h @@ -3,6 +3,7 @@ #include class DownStream; +struct PendingAccount; class DownStreamMgr : public a8::Singleton { private: @@ -25,12 +26,11 @@ class DownStreamMgr : public a8::Singleton private: void OnClientDisconnect(int socket_handle); + std::shared_ptr GetPendingAccount(int socket_handle); void RemovePendingAccount(int socket_handle); private: a8::Attacher timer_attacher_; std::map> socket_hash_; - #if 0 - std::map> pending_account_hash_; - #endif + std::map> pending_account_hash_; };