From 719fbbd05e2ab7897080294fbb2a9cac9c61536e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 21 Apr 2016 22:34:24 +1000 Subject: [PATCH] updateStates is just lazyDestroy, and use it in Conn.Write --- conn.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/conn.go b/conn.go index 6353a6e..bc9cedf 100644 --- a/conn.go +++ b/conn.go @@ -335,8 +335,8 @@ func (c *Conn) deliveryProcessor() { } } -func (c *Conn) updateStates() { - if c.wroteFin && len(c.unackedSends) <= 0 && (c.gotFin || c.closed) { +func (c *Conn) lazyDestroy() { + if c.wroteFin && len(c.unackedSends) <= 1 && (c.gotFin || c.closed) { c.destroy(nil) } } @@ -345,7 +345,7 @@ func (c *Conn) processDelivery(h header, payload []byte) { deliveriesProcessed.Add(1) mu.Lock() defer mu.Unlock() - defer c.updateStates() + defer c.lazyDestroy() defer cond.Broadcast() c.assertHeader(h) c.peerWndSize = h.WndSize @@ -501,17 +501,7 @@ func (c *Conn) Close() (err error) { c.closed = true cond.Broadcast() c.writeFin() - for { - if c.wroteFin && len(c.unackedSends) <= 1 { - // Sent FIN and it's the only thing unacked. - break - } - if c.destroyed { - err = c.err - break - } - cond.Wait() - } + c.lazyDestroy() return }