From 741f5ccdcee0a7cad4a3eca32d06d947cdc460db Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 Apr 2023 11:29:08 +0800 Subject: [PATCH] 1 --- server/wsproxy/GCListener.cc | 23 ++--------------------- server/wsproxy/GCListener.h | 2 +- server/wsproxy/downstream.cc | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/server/wsproxy/GCListener.cc b/server/wsproxy/GCListener.cc index 8b95fb3..a75d7df 100644 --- a/server/wsproxy/GCListener.cc +++ b/server/wsproxy/GCListener.cc @@ -140,28 +140,9 @@ void GCListener::UnInit() tcp_listener_ = nullptr; } -void GCListener::ForwardUpStreamMsg(f8::MsgHdr& hdr) +void GCListener::SendBuf(unsigned short sockhandle, char* buf, int buflen) { - char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen); - f8::PackHead* head = (f8::PackHead*)buff; - head->packlen = hdr.buflen; - head->msgid = hdr.msgid; - head->seqid = hdr.seqid; - head->magic_code = f8::MAGIC_CODE; - head->ext_len = hdr.buflen >> 16; - if (hdr.buflen > 0) { - memmove(buff + sizeof(f8::PackHead), hdr.buf, hdr.buflen); - } - - #ifdef USE_KCP - auto session = GetKcpSessionBySocketHandle(hdr.socket_handle); - if (session) { - session->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen); - } - #else - tcp_listener_->SendClientMsg(hdr.socket_handle, buff, sizeof(f8::PackHead) + head->packlen); - #endif - free(buff); + tcp_listener_->SendClientMsg(sockhandle, buf, buflen); } void GCListener::SendText(unsigned short sockhandle, const std::string& text) diff --git a/server/wsproxy/GCListener.h b/server/wsproxy/GCListener.h index 63d0af5..4e41c7c 100644 --- a/server/wsproxy/GCListener.h +++ b/server/wsproxy/GCListener.h @@ -26,7 +26,7 @@ class GCListener : public a8::Singleton f8::Net_SendMsg(tcp_listener_, socket_handle, 0, msgid, msg); } - void ForwardUpStreamMsg(f8::MsgHdr& hdr); + void SendBuf(unsigned short sockhandle, char* buf, int buflen); void SendText(unsigned short sockhandle, const std::string& text); void ForceCloseClient(unsigned short sockhandle); diff --git a/server/wsproxy/downstream.cc b/server/wsproxy/downstream.cc index adda93e..c030051 100644 --- a/server/wsproxy/downstream.cc +++ b/server/wsproxy/downstream.cc @@ -2,6 +2,8 @@ #include "downstream.h" #include "upstream.h" +#include "longsessionmgr.h" +#include "GCListener.h" #include "ss_proto.pb.h" @@ -18,7 +20,26 @@ void DownStream::ReBindUpStream(std::weak_ptr up) void DownStream::ForwardUpStreamMsg(f8::MsgHdr& hdr) { + char* buff = (char*)malloc(sizeof(f8::PackHead) + hdr.buflen); + f8::PackHead* head = (f8::PackHead*)buff; + head->packlen = hdr.buflen; + head->msgid = hdr.msgid; + head->seqid = hdr.seqid; + head->magic_code = f8::MAGIC_CODE; + head->ext_len = hdr.buflen >> 16; + if (hdr.buflen > 0) { + memmove(buff + sizeof(f8::PackHead), hdr.buf, hdr.buflen); + } + #ifdef USE_KCP + auto session = GetKcpSessionBySocketHandle(hdr.socket_handle); + if (session) { + session->SendClientMsg(buff, sizeof(f8::PackHead) + head->packlen); + } + #else + GCListener::Instance()->SendBuf(hdr.socket_handle, buff, sizeof(f8::PackHead) + head->packlen); + #endif + free(buff); } void DownStream::OnClose()