From c70a830ff7a8a252aea61cd6f056acc636b20778 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Fri, 8 May 2020 09:50:31 +0200 Subject: [PATCH] fix: only connect UDP if requested (#11) We do not need to connect to UDP if we aren't using the UDP connection. --- box/box.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/box/box.go b/box/box.go index 68f67a1..a1d71d2 100644 --- a/box/box.go +++ b/box/box.go @@ -111,7 +111,6 @@ func waitAndRead(pathfinder net.Conn, target *net.UDPConn) { pinIsLow := regexp.MustCompile(`PinState=[lL]`) defer pathfinder.Close() - defer target.Close() for { log.Debug("Reading from Pathfinder.") @@ -147,9 +146,13 @@ func Execute(sendUDP bool, targetAddr string, pathfinderAddr string, pathfinderA Socket = connectSocket(socketPath) SocketPattern = socketPattern } - log.Info("Connecting...") - target := connectUDP(targetAddr) - log.Infof("Connected to target %s", targetAddr) + var target *net.UDPConn + if sendUDP { + log.Info("Connecting UDP...") + target = connectUDP(targetAddr) + log.Infof("Connected to target %s", targetAddr) + defer target.Close() + } pathfinder := connectTCP(pathfinderAddr) log.Infof("Connected to pathfinder %s", pathfinderAddr)