From 3a81c9ed3772d62f8a287713decd34a3ea6a844e Mon Sep 17 00:00:00 2001 From: azw Date: Tue, 25 Apr 2023 03:39:24 +0000 Subject: [PATCH] 1 --- server/wsproxy/jsondatamgr.h | 16 ++++++++++++++++ server/wsproxy/kcpsession.cc | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/server/wsproxy/jsondatamgr.h b/server/wsproxy/jsondatamgr.h index b87b660..255b8da 100644 --- a/server/wsproxy/jsondatamgr.h +++ b/server/wsproxy/jsondatamgr.h @@ -2,6 +2,20 @@ #include +struct KcpConf +{ + int sndwnd = 128; + int rcvwnd = 128; + + int nodelay = 2; + int interval = 10; + int resend = 2; + int nc = 1; + + int rx_minrto = 0; + int fastresend = 1; +}; + class JsonDataMgr : public a8::Singleton { private: @@ -16,6 +30,7 @@ class JsonDataMgr : public a8::Singleton int GetUdpPort() { return udp_port_; } std::shared_ptr GetConf(); void TraverseMaster(std::function cb); + const KcpConf& GetKcpConf() { return kcp_conf_; } private: std::string work_path_ = "../config"; @@ -23,4 +38,5 @@ class JsonDataMgr : public a8::Singleton a8::XObject master_cluster_json_; std::string udp_host_; int udp_port_ = 0; + KcpConf kcp_conf_ = {}; }; diff --git a/server/wsproxy/kcpsession.cc b/server/wsproxy/kcpsession.cc index c52e9e8..efe4b3d 100644 --- a/server/wsproxy/kcpsession.cc +++ b/server/wsproxy/kcpsession.cc @@ -7,6 +7,7 @@ #include "kcpsession.h" #include "longsessionmgr.h" +#include "jsondatamgr.h" #include "app.h" static const int DEFAULT_MAX_RECV_BUFFERSIZE = 1024 * 64; @@ -37,10 +38,18 @@ void KcpSession::Init(int socket_handle) socket_handle_ = socket_handle; secret_key_ = App::Instance()->NewUuid(); kcp_ = ikcp_create(socket_handle_, (void*)this); +#if 1 + const KcpConf& kcp_conf = JsonDataMgr::Instance()->GetKcpConf(); + ikcp_wndsize(kcp_, kcp_conf.sndwnd, kcp_conf.rcvwnd); + ikcp_nodelay(kcp_, kcp_conf.nodelay, kcp_conf.interval, kcp_conf.resend, kcp_conf.nc); + kcp_->rx_minrto = kcp_conf.rx_minrto; + kcp_->fastresend = kcp_conf.fastresend; +#else ikcp_wndsize(kcp_, 128, 128); ikcp_nodelay(kcp_, 2, 10, 2, 1); kcp_->rx_minrto = 10; kcp_->fastresend = 1; +#endif kcp_->output = UdpOutput; init_tick_ = a8::XGetTickCount(); }