From 0e7ea57efb697b693982a4c0a01660d036161e96 Mon Sep 17 00:00:00 2001 From: David Fifield Date: Sun, 1 Aug 2021 22:50:24 -0600 Subject: [PATCH] Simplify break from the packing loop in sendLoop. --- dnstt-server/main.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dnstt-server/main.go b/dnstt-server/main.go index 6750bc8..04f03b0 100644 --- a/dnstt-server/main.go +++ b/dnstt-server/main.go @@ -585,7 +585,6 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <- // overflow the capacity of the DNS response, we stash // to be bundled into a future response. timer := time.NewTimer(maxResponseDelay) - loop: for { var p []byte select { @@ -598,16 +597,12 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <- // If there's another response waiting // to be sent, wait no longer for a // payload for this one. - break loop case <-timer.C: - break loop case p = <-ttConn.Unstash(rec.ClientID): default: select { case nextRec = <-ch: - break loop case <-timer.C: - break loop case p = <-ttConn.Unstash(rec.ClientID): case p = <-ttConn.OutgoingQueue(rec.ClientID): } @@ -618,6 +613,12 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <- // from this bundle. timer.Reset(0) + if len(p) == 0 { + // timer expired or receive on ch, we + // are done with this response. + break + } + limit -= 2 + len(p) if payload.Len() == 0 { // No packet length check for the first @@ -628,7 +629,7 @@ func sendLoop(dnsConn net.PacketConn, ttConn *turbotunnel.QueuePacketConn, ch <- // Stash this packet to send in the next // response. ttConn.Stash(p, rec.ClientID) - break loop + break } if int(uint16(len(p))) != len(p) { panic(len(p))