Skip to content

Commit

Permalink
Clear sending queue when peer closed
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Jun 23, 2016
1 parent ab710f2 commit 0613d0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions transport/internet/kcp/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions transport/internet/kcp/kcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0613d0c

Please sign in to comment.