This commit is contained in:
azw 2023-04-25 03:39:24 +00:00
parent 499114b744
commit 3a81c9ed37
2 changed files with 25 additions and 0 deletions

View File

@ -2,6 +2,20 @@
#include <a8/singleton.h>
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<JsonDataMgr>
{
private:
@ -16,6 +30,7 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
int GetUdpPort() { return udp_port_; }
std::shared_ptr<a8::XObject> GetConf();
void TraverseMaster(std::function<void (int, std::string, int)> cb);
const KcpConf& GetKcpConf() { return kcp_conf_; }
private:
std::string work_path_ = "../config";
@ -23,4 +38,5 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
a8::XObject master_cluster_json_;
std::string udp_host_;
int udp_port_ = 0;
KcpConf kcp_conf_ = {};
};

View File

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