[VOL-4292] OpenOLT Adapter changes for gRPC migration
Change-Id: I5af2125f2c2f53ffc78c474a94314bba408f8bae
diff --git a/vendor/github.com/phayes/freeport/freeport.go b/vendor/github.com/phayes/freeport/freeport.go
new file mode 100644
index 0000000..fcfb6ba
--- /dev/null
+++ b/vendor/github.com/phayes/freeport/freeport.go
@@ -0,0 +1,49 @@
+package freeport
+
+import (
+ "net"
+)
+
+// GetFreePort asks the kernel for a free open port that is ready to use.
+func GetFreePort() (int, error) {
+ addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
+ if err != nil {
+ return 0, err
+ }
+
+ l, err := net.ListenTCP("tcp", addr)
+ if err != nil {
+ return 0, err
+ }
+ defer l.Close()
+ return l.Addr().(*net.TCPAddr).Port, nil
+}
+
+// GetPort is deprecated, use GetFreePort instead
+// Ask the kernel for a free open port that is ready to use
+func GetPort() int {
+ port, err := GetFreePort()
+ if err != nil {
+ panic(err)
+ }
+ return port
+}
+
+// GetFreePort asks the kernel for free open ports that are ready to use.
+func GetFreePorts(count int) ([]int, error) {
+ var ports []int
+ for i := 0; i < count; i++ {
+ addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
+ if err != nil {
+ return nil, err
+ }
+
+ l, err := net.ListenTCP("tcp", addr)
+ if err != nil {
+ return nil, err
+ }
+ defer l.Close()
+ ports = append(ports, l.Addr().(*net.TCPAddr).Port)
+ }
+ return ports, nil
+}