This commit is contained in:
azw 2023-04-25 03:31:56 +00:00
parent 5da25c735d
commit 499114b744
5 changed files with 25 additions and 8 deletions

View File

@ -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);
}
}
}

View File

@ -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<UpStream> 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);
}
}

View File

@ -12,6 +12,7 @@ class DownStream
std::weak_ptr<UpStream> GetUpStream() const { return up_; }
void ReBindUpStream(std::weak_ptr<UpStream> up);
bool IsLongSession() { return is_long_session_; }
void ProcCMMsg(f8::MsgHdr& hdr, int tag);
void ForwardUpStreamMsg(f8::MsgHdr& hdr);
void OnClose();

View File

@ -20,3 +20,8 @@ void LongSession::Update(long long tick)
{
GetKcpSession()->Update(tick);
}
void LongSession::UpdatePing()
{
last_ping_tick_ = a8::XGetTickCount();
}

View File

@ -16,7 +16,9 @@ class LongSession
void Update(long long tick);
std::shared_ptr<KcpSession> GetKcpSession() { return kcp_session_; }
void UpdatePing();
private:
long long last_ping_tick_ = 0;
std::shared_ptr<KcpSession> kcp_session_;
};