1
This commit is contained in:
parent
22cc01609a
commit
10d34b25ce
@ -129,10 +129,24 @@ class KcpSession
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Init(a8::UdpPacket* pkt)
|
void Init(int socket_handle, a8::UdpPacket* pkt)
|
||||||
{
|
{
|
||||||
remote_key_ = pkt->GetRemoteKey();
|
remote_key_ = pkt->GetRemoteKey();
|
||||||
remote_addr_ = pkt->remote_addr;
|
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)
|
void SendMsg(unsigned short msgid, const ::google::protobuf::Message& msg)
|
||||||
@ -147,6 +161,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ikcpcb* kcp_ = nullptr;
|
ikcpcb* kcp_ = nullptr;
|
||||||
|
int socket_handle_ = 0;
|
||||||
long long remote_key_ = 0;
|
long long remote_key_ = 0;
|
||||||
sockaddr_in remote_addr_ = {};
|
sockaddr_in remote_addr_ = {};
|
||||||
};
|
};
|
||||||
@ -247,8 +262,9 @@ void GCListener::ProcUdpPacket(a8::UdpPacket* pkt)
|
|||||||
if (!session) {
|
if (!session) {
|
||||||
++kcp_socket_handle_;
|
++kcp_socket_handle_;
|
||||||
session = std::make_shared<KcpSession>();
|
session = std::make_shared<KcpSession>();
|
||||||
session->Init(pkt);
|
session->Init(kcp_socket_handle_, pkt);
|
||||||
kcp_session_addr_hash_[key] = session;
|
kcp_session_addr_hash_[key] = session;
|
||||||
|
kcp_session_handle_hash_[kcp_socket_handle_] = session;
|
||||||
}
|
}
|
||||||
session->OnRecvPacket(pkt);
|
session->OnRecvPacket(pkt);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user