From fb9fefd1aae3d638a70a94551ab515076943c0ed Mon Sep 17 00:00:00 2001 From: azw Date: Thu, 13 Apr 2023 22:45:28 +0000 Subject: [PATCH] 1 --- server/wsproxy/mastermgr.cc | 20 +++++++++++--------- server/wsproxy/mastermgr.h | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index f7ab86b..8e30eec 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -87,7 +87,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, int is_reconnect, int proto_version) { - if (GetContextIdBySocket(hdr.socket_handle) != 0) { + if (GetRequestBySocket(hdr.socket_handle)) { return; } unsigned int code = 0; @@ -121,9 +121,9 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, msg.set_proto_version(proto_version); svr->SendMsg(msg); - pending_socket_hash_[hdr.socket_handle] = curr_context_id_; - assert(pending_request_hash_.find(curr_context_id_) == pending_request_hash_.end()); - pending_request_hash_[curr_context_id_] = req; + pending_socket_hash_[hdr.socket_handle] = req; + assert(pending_context_hash_.find(curr_context_id_) == pending_context_hash_.end()); + pending_context_hash_[curr_context_id_] = req; req->timer_wp = f8::Timer::Instance()->SetTimeoutWp (1000 * 10, [req] (int event, const a8::Args* args) @@ -148,6 +148,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, void MasterMgr::RemoveRequest(int socket_handle, long long context_id, bool auto_free) { + #if 0 if (context_id == GetContextIdBySocket(socket_handle)) { auto req = GetRequestByContextId(context_id); if (req) { @@ -158,19 +159,20 @@ void MasterMgr::RemoveRequest(int socket_handle, long long context_id, bool auto free(req->hdr_copy); } } - pending_request_hash_.erase(context_id); + pending_context_hash_.erase(context_id); pending_socket_hash_.erase(socket_handle); } + #endif } -long long MasterMgr::GetContextIdBySocket(int socket_handle) +std::shared_ptr MasterMgr::GetRequestBySocket(int socket_handle) { auto itr = pending_socket_hash_.find(socket_handle); - return itr != pending_socket_hash_.end() ? itr->second : 0; + return itr != pending_socket_hash_.end() ? itr->second : nullptr; } std::shared_ptr MasterMgr::GetRequestByContextId(long long context_id) { - auto itr = pending_request_hash_.find(context_id); - return itr != pending_request_hash_.end() ? itr->second : nullptr; + auto itr = pending_context_hash_.find(context_id); + return itr != pending_context_hash_.end() ? itr->second : nullptr; } diff --git a/server/wsproxy/mastermgr.h b/server/wsproxy/mastermgr.h index c963345..37d5c5d 100644 --- a/server/wsproxy/mastermgr.h +++ b/server/wsproxy/mastermgr.h @@ -36,14 +36,14 @@ class MasterMgr : public a8::Singleton void RemoveRequest(int socket_handle, long long context_id, bool auto_free); private: - long long GetContextIdBySocket(int socket_handle); + std::shared_ptr GetRequestBySocket(int socket_handle); std::shared_ptr GetRequestByContextId(long long context_id); std::shared_ptr GetConnById(int instance_id); private: long long curr_context_id_ = 0; std::map> mastersvr_hash_; - std::map pending_socket_hash_; - std::map> pending_request_hash_; + std::map> pending_socket_hash_; + std::map> pending_context_hash_; };