From 10d34b25cead3d1eee865387f5ae38f1c196a906 Mon Sep 17 00:00:00 2001 From: azw Date: Mon, 17 Apr 2023 07:23:00 +0000 Subject: [PATCH] 1 --- server/wsproxy/GCListener.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/server/wsproxy/GCListener.cc b/server/wsproxy/GCListener.cc index 9c47c52..4f7893d 100644 --- a/server/wsproxy/GCListener.cc +++ b/server/wsproxy/GCListener.cc @@ -129,10 +129,24 @@ class KcpSession { public: - void Init(a8::UdpPacket* pkt) + void Init(int socket_handle, a8::UdpPacket* pkt) { remote_key_ = pkt->GetRemoteKey(); remote_addr_ = pkt->remote_addr; + socket_handle_ = socket_handle; + kcp_ = ikcp_create(socket_handle_, (void*)this); + ikcp_wndsize(kcp_, 128, 128); + ikcp_nodelay(kcp_, 2, 10, 2, 1); + kcp_->rx_minrto = 10; + kcp_->fastresend = 1; + } + + void UnInit() + { + if (kcp_) { + ikcp_release(kcp_); + kcp_ = nullptr; + } } void SendMsg(unsigned short msgid, const ::google::protobuf::Message& msg) @@ -147,6 +161,7 @@ public: private: ikcpcb* kcp_ = nullptr; + int socket_handle_ = 0; long long remote_key_ = 0; sockaddr_in remote_addr_ = {}; }; @@ -247,8 +262,9 @@ void GCListener::ProcUdpPacket(a8::UdpPacket* pkt) if (!session) { ++kcp_socket_handle_; session = std::make_shared(); - session->Init(pkt); + session->Init(kcp_socket_handle_, pkt); kcp_session_addr_hash_[key] = session; + kcp_session_handle_hash_[kcp_socket_handle_] = session; } session->OnRecvPacket(pkt); }