purge outgoing segments when closing

This commit is contained in:
xtaci
2019-11-01 14:28:14 +00:00
parent 62a262c330
commit 9313fe25dd
2 changed files with 14 additions and 0 deletions
+12
View File
@@ -1051,3 +1051,15 @@ func (kcp *KCP) remove_front(q []segment, n int) []segment {
}
return q[n:]
}
// Release all cached outgoing segments
func (kcp *KCP) ReleaseTX() {
for k := range kcp.snd_queue {
xmitBuf.Put(kcp.snd_queue[k].data)
}
for k := range kcp.snd_buf {
xmitBuf.Put(kcp.snd_buf[k].data)
}
kcp.snd_queue = nil
kcp.snd_buf = nil
}
+2
View File
@@ -353,6 +353,8 @@ func (s *UDPSession) Close() error {
s.mu.Lock()
s.kcp.flush(false)
s.uncork()
// release pending segments
s.kcp.ReleaseTX()
s.mu.Unlock()
if s.l != nil { // belongs to listener