From 7ddf7ddad667dba3a0a664382927253b3c129992 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 10 Dec 2013 18:49:07 -0800 Subject: [PATCH] packer/rpc: remove the PortRange stuff --- packer/plugin/plugin.go | 3 --- packer/rpc/port.go | 30 ------------------------------ packer/rpc/port_test.go | 38 -------------------------------------- 3 files changed, 71 deletions(-) delete mode 100644 packer/rpc/port.go delete mode 100644 packer/rpc/port_test.go diff --git a/packer/plugin/plugin.go b/packer/plugin/plugin.go index 8012ffc4f..63c19b9b3 100644 --- a/packer/plugin/plugin.go +++ b/packer/plugin/plugin.go @@ -62,9 +62,6 @@ func Server() (*packrpc.Server, error) { log.Printf("Plugin minimum port: %d\n", minPort) log.Printf("Plugin maximum port: %d\n", maxPort) - // Set the RPC port range - packrpc.PortRange(int(minPort), int(maxPort)) - var address string var listener net.Listener for port := minPort; port <= maxPort; port++ { diff --git a/packer/rpc/port.go b/packer/rpc/port.go deleted file mode 100644 index bf917780b..000000000 --- a/packer/rpc/port.go +++ /dev/null @@ -1,30 +0,0 @@ -package rpc - -import ( - "fmt" - "net" -) - -var portRangeMin int = 10000 -var portRangeMax int = 11000 - -// This sets the port range that the RPC stuff will use when creating -// new temporary servers. Some RPC calls require the creation of temporary -// RPC servers. These allow you to pick a range these bind to. -func PortRange(min, max int) { - portRangeMin = min - portRangeMax = max -} - -// This finds an open port in the given range and returns a listener -// bound to that port. -func netListenerInRange(min, max int) net.Listener { - for port := min; port <= max; port++ { - l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) - if err == nil { - return l - } - } - - return nil -} diff --git a/packer/rpc/port_test.go b/packer/rpc/port_test.go deleted file mode 100644 index 3e6afef40..000000000 --- a/packer/rpc/port_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package rpc - -import ( - "net" - "strings" - "testing" -) - -func addrPort(address net.Addr) string { - parts := strings.Split(address.String(), ":") - return parts[len(parts)-1] -} - -func Test_netListenerInRange(t *testing.T) { - // Open up port 10000 so that we take up a port - L1000, err := net.Listen("tcp", "127.0.0.1:11000") - defer L1000.Close() - if err != nil { - t.Fatalf("bad: %s", err) - } - - if err == nil { - // Verify it selects an open port - L := netListenerInRange(11000, 11005) - if L == nil { - t.Fatal("L should not be nil") - } - if addrPort(L.Addr()) != "11001" { - t.Fatalf("bad: %s", L.Addr()) - } - - // Returns nil if there are no open ports - L = netListenerInRange(11000, 11000) - if L != nil { - t.Fatalf("bad: %#v", L) - } - } -}