From 499114b7444000ad13a82e4d556d1b9bcb4be432 Mon Sep 17 00:00:00 2001 From: azw Date: Tue, 25 Apr 2023 03:31:56 +0000 Subject: [PATCH] 1 --- server/wsproxy/app.cc | 9 +-------- server/wsproxy/downstream.cc | 16 ++++++++++++++++ server/wsproxy/downstream.h | 1 + server/wsproxy/longsession.cc | 5 +++++ server/wsproxy/longsession.h | 2 ++ 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index a5f2b11..3c99376 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -441,14 +441,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag) } else { auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr.socket_handle); if (auto down = down_wp.lock(); !down_wp.expired()) { - bool need_sync_up = true; - #if 0 - if (hdr.msgid == ss::_SS_CMPing && down->IsLongSession()) { - } - #endif - if (!down->GetUpStream().expired() && need_sync_up) { - down->GetUpStream().lock()->ForwardClientMsg(hdr); - } + down->ProcCMMsg(hdr, tag); } } } diff --git a/server/wsproxy/downstream.cc b/server/wsproxy/downstream.cc index 3576683..868a806 100644 --- a/server/wsproxy/downstream.cc +++ b/server/wsproxy/downstream.cc @@ -7,6 +7,7 @@ #include "longsession.h" #include "kcpsession.h" +#include "ss_msgid.pb.h" #include "ss_proto.pb.h" void DownStream::Init(int socket_handle, std::weak_ptr up) @@ -53,3 +54,18 @@ void DownStream::OnClose() LongSessionMgr::Instance()->DelSession(socket_handle_); } } + +void DownStream::ProcCMMsg(f8::MsgHdr& hdr, int tag) +{ + if (hdr.msgid == ss::_SS_CMPing && IsLongSession() && tag == ST_Tcp) { + ss::SS_Ping msg; + GCListener::Instance()->SendMsgEx(socket_handle_, ss::_SS_CMPing, msg); + if (!long_session_wp_.expired()) { + long_session_wp_.lock()->UpdatePing(); + } + return; + } + if (!GetUpStream().expired()) { + GetUpStream().lock()->ForwardClientMsg(hdr); + } +} diff --git a/server/wsproxy/downstream.h b/server/wsproxy/downstream.h index 196fa09..1a017e7 100644 --- a/server/wsproxy/downstream.h +++ b/server/wsproxy/downstream.h @@ -12,6 +12,7 @@ class DownStream std::weak_ptr GetUpStream() const { return up_; } void ReBindUpStream(std::weak_ptr up); bool IsLongSession() { return is_long_session_; } + void ProcCMMsg(f8::MsgHdr& hdr, int tag); void ForwardUpStreamMsg(f8::MsgHdr& hdr); void OnClose(); diff --git a/server/wsproxy/longsession.cc b/server/wsproxy/longsession.cc index e261182..2dbcb3b 100644 --- a/server/wsproxy/longsession.cc +++ b/server/wsproxy/longsession.cc @@ -20,3 +20,8 @@ void LongSession::Update(long long tick) { GetKcpSession()->Update(tick); } + +void LongSession::UpdatePing() +{ + last_ping_tick_ = a8::XGetTickCount(); +} diff --git a/server/wsproxy/longsession.h b/server/wsproxy/longsession.h index 284e27c..4218829 100644 --- a/server/wsproxy/longsession.h +++ b/server/wsproxy/longsession.h @@ -16,7 +16,9 @@ class LongSession void Update(long long tick); std::shared_ptr GetKcpSession() { return kcp_session_; } + void UpdatePing(); private: + long long last_ping_tick_ = 0; std::shared_ptr kcp_session_; };