Skip to content

Commit

Permalink
fix: only connect UDP if requested (#11)
Browse files Browse the repository at this point in the history
We do not need to connect to UDP if we aren't using the UDP connection.
  • Loading branch information
hairmare authored May 8, 2020
1 parent 6fd2485 commit c70a830
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions box/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c70a830

Please sign in to comment.