diff --git a/port_forwarder.go b/port_forwarder.go index fe0d7d80e..593b70fe7 100644 --- a/port_forwarder.go +++ b/port_forwarder.go @@ -26,23 +26,24 @@ func NewPortForwarder(session *Session, name string, remotePort int) *PortForwar } } -// ListenTCP calls listen on the chosen local TCP port. Zero picks an arbitrary port. -// It is provided for the convenience of callers of ForwardToLocalPort. -func Listen(port int) (net.Listener, error) { +// ListenTCP calls listen on the chosen local TCP port. Zero picks an +// arbitrary port. It is provided for the convenience of callers of +// ForwardToListener. +func ListenTCP(port int) (net.Listener, error) { return net.Listen("tcp", fmt.Sprintf(":%d", port)) } -// ForwardToLocalPort forwards traffic between the container's remote -// port and a local TCP port, which must already be listening for +// ForwardToListener forwards traffic between the container's remote +// port and a local port, which must already be listening for // connections. (Accepting a listener rather than a port number avoids // races against other processes opening ports, and against a client // connecting to the socket prematurely.) // -// ForwardToLocalPort accepts and handles connections on the local -// port until it encounters the first error, which may include context +// ForwardToListener accepts and handles connections on the local port +// until it encounters the first error, which may include context // cancellation. Its error result is always non-nil. The caller is // responsible for closing the listening port. -func (fwd *PortForwarder) ForwardToLocalPort(ctx context.Context, listen net.Listener) (err error) { +func (fwd *PortForwarder) ForwardToListener(ctx context.Context, listen net.Listener) (err error) { id, err := fwd.shareRemotePort(ctx) if err != nil { return err diff --git a/port_forwarder_test.go b/port_forwarder_test.go index 68b658b6b..d6a4e7708 100644 --- a/port_forwarder_test.go +++ b/port_forwarder_test.go @@ -46,7 +46,7 @@ func TestPortForwarderStart(t *testing.T) { } defer testServer.Close() - listen, err := Listen(8000) // local port + listen, err := ListenTCP(8000) // local port if err != nil { t.Fatal(err) } @@ -58,7 +58,7 @@ func TestPortForwarderStart(t *testing.T) { done := make(chan error) go func() { const name, remote = "ssh", 8000 - done <- NewPortForwarder(session, name, remote).ForwardToLocalPort(ctx, listen) + done <- NewPortForwarder(session, name, remote).ForwardToListener(ctx, listen) }() go func() {