Explorar o código

Clear sending queue when peer closed

v2ray %!s(int64=9) %!d(string=hai) anos
pai
achega
0613d0cf22
Modificáronse 2 ficheiros con 16 adicións e 0 borrados
  1. 3 0
      transport/internet/kcp/connection.go
  2. 13 0
      transport/internet/kcp/kcp.go

+ 3 - 0
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) {

+ 13 - 0
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
+}