Commit 7ddf7dda authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: remove the PortRange stuff

parent 3b3d09cb
......@@ -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++ {
......
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
}
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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment