1
This commit is contained in:
parent
10d34b25ce
commit
393bdfff49
@ -129,8 +129,20 @@ class KcpSession
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Init(int socket_handle, a8::UdpPacket* pkt)
|
static int UdpOutput(const char *buf, int len, ikcpcb *kcp, void *user)
|
||||||
{
|
{
|
||||||
|
KcpSession* session = (KcpSession*)user;
|
||||||
|
a8::UdpPacket* pkt = new a8::UdpPacket();
|
||||||
|
pkt->buf = buf;
|
||||||
|
pkt->buf_len = len;
|
||||||
|
pkt->remote_addr = session->remote_addr_;
|
||||||
|
session->udp_listener_->SendUdpPacket(pkt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init(a8::UdpListener* udp_listener, int socket_handle, a8::UdpPacket* pkt)
|
||||||
|
{
|
||||||
|
udp_listener_ = udp_listener;
|
||||||
remote_key_ = pkt->GetRemoteKey();
|
remote_key_ = pkt->GetRemoteKey();
|
||||||
remote_addr_ = pkt->remote_addr;
|
remote_addr_ = pkt->remote_addr;
|
||||||
socket_handle_ = socket_handle;
|
socket_handle_ = socket_handle;
|
||||||
@ -139,6 +151,7 @@ public:
|
|||||||
ikcp_nodelay(kcp_, 2, 10, 2, 1);
|
ikcp_nodelay(kcp_, 2, 10, 2, 1);
|
||||||
kcp_->rx_minrto = 10;
|
kcp_->rx_minrto = 10;
|
||||||
kcp_->fastresend = 1;
|
kcp_->fastresend = 1;
|
||||||
|
kcp_->output = KcpSession::UdpOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnInit()
|
void UnInit()
|
||||||
@ -149,6 +162,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SendMsg(unsigned short msgid, const ::google::protobuf::Message& msg)
|
void SendMsg(unsigned short msgid, const ::google::protobuf::Message& msg)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -160,6 +178,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
a8::UdpListener* udp_listener_ = nullptr;
|
||||||
ikcpcb* kcp_ = nullptr;
|
ikcpcb* kcp_ = nullptr;
|
||||||
int socket_handle_ = 0;
|
int socket_handle_ = 0;
|
||||||
long long remote_key_ = 0;
|
long long remote_key_ = 0;
|
||||||
@ -262,7 +281,7 @@ 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(kcp_socket_handle_, pkt);
|
session->Init(udp_listener_.get(), kcp_socket_handle_, pkt);
|
||||||
kcp_session_addr_hash_[key] = session;
|
kcp_session_addr_hash_[key] = session;
|
||||||
kcp_session_handle_hash_[kcp_socket_handle_] = session;
|
kcp_session_handle_hash_[kcp_socket_handle_] = session;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user