This commit is contained in:
azw 2023-04-17 07:23:00 +00:00
parent 22cc01609a
commit 10d34b25ce

View File

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