From 84a95f2daf43e667301f193bb43db07f08fbaec7 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 27 Mar 2015 11:53:56 +0000 Subject: [PATCH] refactor: concentrate frame appending code in one place --- router/forwarder.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/router/forwarder.go b/router/forwarder.go index b4bff3a4..791033c0 100644 --- a/router/forwarder.go +++ b/router/forwarder.go @@ -263,14 +263,7 @@ func (fwd *Forwarder) run() { fwd.conn.Log("Effective PMTU verified at", epmtu) } case frame := <-fwd.ch: - if frame == nil { - fwd.drain() - return - } - if !fwd.appendFrame(frame) { - fwd.logDrop(frame) - } - if !fwd.accumulateAndSendFrames() { + if !fwd.accumulateAndSendFrames(frame) { return } } @@ -306,10 +299,17 @@ func (fwd *Forwarder) attemptVerifyEffectivePMTU() { // franes get sent to the forwarder, we can be going around this loop // forever. That is bad since there may be other stuff for us to do, // i.e. the other branches in of the run loop. -func (fwd *Forwarder) accumulateAndSendFrames() bool { +func (fwd *Forwarder) accumulateAndSendFrames(frame *ForwardedFrame) bool { + if frame == nil { + fwd.drain() + return false + } + if !fwd.appendFrame(frame) { + fwd.logDrop(frame) + } for { select { - case frame := <-fwd.ch: + case frame = <-fwd.ch: if frame == nil { fwd.drain() return false