This commit is contained in:
aozhiwei 2023-04-23 18:59:57 +08:00
parent 1279895717
commit 5447397c21
2 changed files with 2 additions and 43 deletions

View File

@ -82,43 +82,10 @@ void KcpSession::UpdateInput()
if (buflen <= 0) {
return;
}
unsigned int already_read_bytes = 0;
do {
if (already_read_bytes < buflen) {
int read_bytes = std::min(buflen - already_read_bytes,
(unsigned int)max_packet_len_ - recv_bufflen_);
if (read_bytes > 0) {
memmove(&recv_buff_[recv_bufflen_], buf + already_read_bytes, read_bytes);
recv_bufflen_ += read_bytes;
already_read_bytes += read_bytes;
}
}
int offset = 0;
int prev_offset = 0;
do {
prev_offset = offset;
DecodePacket(recv_buff_, offset, recv_bufflen_);
} while (prev_offset < offset && offset < recv_bufflen_);
if (offset > 0 && offset < recv_bufflen_){
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
}
recv_bufflen_ -= offset;
if (recv_bufflen_ >= max_packet_len_) {
//收到超长包
#if 1
abort();
#else
//Close();
#endif
return;
}
} while (already_read_bytes < buflen);
OnSocketRead(buf, buflen);
}
void KcpSession::DecodePacket(char* buf, int& offset, unsigned int buflen)
void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
{
//packagelen + msgid + magiccode + msgbody
//2 + 2 + 4+ xx + \0 + xx
@ -150,8 +117,3 @@ void KcpSession::DecodePacket(char* buf, int& offset, unsigned int buflen)
f8::UdpLog::Instance()->Warning("收到client非法数据包", {});
}
}
void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
{
}

View File

@ -25,9 +25,6 @@ public:
protected:
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override;
private:
void DecodePacket(char* buf, int& offset, unsigned int buflen);
private:
long long init_tick_ = 0;
long long secret_key_ = 0;