From 9198763f78781cf44acdb4f690b67f491b9e8f9f Mon Sep 17 00:00:00 2001 From: cnbatch Date: Sat, 4 Nov 2023 16:22:47 +0800 Subject: [PATCH] ACK bug fix. --- src/3rd_party/ikcp.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/3rd_party/ikcp.cpp b/src/3rd_party/ikcp.cpp index c4e26dc..6ec1adf 100644 --- a/src/3rd_party/ikcp.cpp +++ b/src/3rd_party/ikcp.cpp @@ -543,8 +543,15 @@ namespace KCP if (auto iter = this->snd_buf.find(sn); iter != this->snd_buf.end()) { std::shared_ptr seg = iter->second; - this->resendts_buf[seg->resendts].erase(sn); - this->fastack_buf[seg->fastack].erase(sn); + + if (auto resendts_iter = this->resendts_buf.find(seg->resendts); resendts_iter != this->resendts_buf.end()) + if (auto um_iter = resendts_iter->second.find(sn); um_iter != resendts_iter->second.end()) + resendts_iter->second.erase(um_iter); + + if (auto fastack_iter = this->fastack_buf.find(seg->resendts); fastack_iter != this->fastack_buf.end()) + if (auto um_iter = fastack_iter->second.find(sn); um_iter != fastack_iter->second.end()) + fastack_iter->second.erase(um_iter); + this->snd_buf.erase(iter); } } @@ -556,10 +563,16 @@ namespace KCP ++next; uint32_t sn = iter->first; std::shared_ptr seg = iter->second; - if (una > iter->first) + if (una > sn) { - this->resendts_buf[seg->resendts].erase(sn); - this->fastack_buf[seg->fastack].erase(sn); + if (auto resendts_iter = this->resendts_buf.find(seg->resendts); resendts_iter != this->resendts_buf.end()) + if (auto um_iter = resendts_iter->second.find(sn); um_iter != resendts_iter->second.end()) + resendts_iter->second.erase(um_iter); + + if (auto fastack_iter = this->fastack_buf.find(seg->resendts); fastack_iter != this->fastack_buf.end()) + if (auto um_iter = fastack_iter->second.find(sn); um_iter != fastack_iter->second.end()) + fastack_iter->second.erase(um_iter); + this->snd_buf.erase(iter); } else break;