Skip to content

Commit

Permalink
purge outgoing segments when closing
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Nov 1, 2019
1 parent 62a262c commit 9313fe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9313fe2

Please sign in to comment.