This commit is contained in:
aozhiwei 2023-04-24 11:51:40 +08:00
parent 9ae217eea5
commit 52188b8ada
2 changed files with 8 additions and 5 deletions

View File

@ -13,6 +13,8 @@ void DownStream::Init(int socket_handle, std::weak_ptr<UpStream> up)
{
socket_handle_ = socket_handle;
up_ = up;
long_session_wp_ = LongSessionMgr::Instance()->GetSession(socket_handle_);
is_long_session_ = !long_session_wp_.expired();
}
void DownStream::ReBindUpStream(std::weak_ptr<UpStream> up)
@ -33,9 +35,8 @@ void DownStream::ForwardUpStreamMsg(f8::MsgHdr& hdr)
memmove(buff + sizeof(f8::PackHead), hdr.buf, hdr.buflen);
}
auto session = LongSessionMgr::Instance()->GetSession(hdr.socket_handle);
if (session) {
session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen);
if (auto long_session = long_session_wp_.lock(); !long_session_wp_.expired()) {
long_session->GetKcpSession()->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen);
} else {
GCListener::Instance()->SendBuf(hdr.socket_handle, buff, sizeof(f8::PackHead) + head->packlen);
}
@ -48,8 +49,7 @@ void DownStream::OnClose()
ss::SS_WSP_SocketDisconnect msg;
GetUpStream().lock()->SendMsg(socket_handle_, msg);
}
auto session = LongSessionMgr::Instance()->GetSession(socket_handle_);
if (session) {
if (auto long_session = long_session_wp_.lock(); !long_session_wp_.expired()) {
} else {

View File

@ -1,6 +1,7 @@
#pragma once
class UpStream;
class LongSession;
class DownStream
{
public:
@ -17,4 +18,6 @@ class DownStream
private:
int socket_handle_ = a8::INVALID_SOCKET_HANDLE;
std::weak_ptr<UpStream> up_;
bool is_long_session_ = false;
std::weak_ptr<LongSession> long_session_wp_;
};