From 0613d0cf221c557ef2edb0d0accd30d84addb23e Mon Sep 17 00:00:00 2001 From: v2ray Date: Thu, 23 Jun 2016 23:17:17 +0200 Subject: [PATCH] Clear sending queue when peer closed --- transport/internet/kcp/connection.go | 3 +++ transport/internet/kcp/kcp.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 56dac8ac..93b9b841 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -358,6 +358,9 @@ func (this *Connection) MarkPeerClose() { if this.state == ConnStateActive { this.state = ConnStatePeerClosed } + this.kcpAccess.Lock() + this.kcp.ClearSendQueue() + this.kcpAccess.Unlock() } func (this *Connection) kcpInput(data []byte) { diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index bf4df0e9..65d96ffd 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -842,3 +842,16 @@ func (kcp *KCP) WndSize(sndwnd, rcvwnd int) int { func (kcp *KCP) WaitSnd() int { return len(kcp.snd_buf) + len(kcp.snd_queue) } + +func (this *KCP) ClearSendQueue() { + for _, seg := range this.snd_queue { + seg.Release() + } + this.snd_queue = nil + + for _, seg := range this.snd_buf { + seg.Release() + } + + this.snd_buf = nil +}