dnet

package
v2.20.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package dnet contains alternative net.Conn implementations.

Index

Constants

View Source
const K8sPFScheme = "k8spf"

Variables

This section is empty.

Functions

func FreePortsTCP added in v2.12.0

func FreePortsTCP(count int) ([]*net.TCPAddr, error)

FreePortsTCP uses net.Listen repeatedly to choose free TCP ports for the localhost. It then immediately closes the listeners and returns the addresses that were allocated.

NOTE: Since the listeners are closed, there's a chance that someone else might allocate the returned addresses before they are actually used. The chances are slim though, since tests show that in most cases (at least on macOS and Linux), the same address isn't allocated for a while even if the allocation is made from different processes.

func NewResolver added in v2.19.0

func NewResolver(ctx context.Context) resolver.Builder

func WithPortForwardDialer added in v2.17.0

func WithPortForwardDialer(ctx context.Context, pf PortForwardDialer) context.Context

Types

type Addr added in v2.14.1

type Addr struct {
	Net  string
	Addr string
}

func (Addr) Network added in v2.14.1

func (a Addr) Network() string

func (Addr) String added in v2.14.1

func (a Addr) String() string

type Conn

type Conn interface {
	net.Conn

	// Wait until either the connection is Close()d, or one of Read() or Write() encounters an
	// error (*not* counting errors caused by deadlines).  If this returns because Close() was
	// called, nil is returned; otherwise the triggering error is returned.
	//
	// Essentially: Wait until the connection is finished.
	Wait() error
}

Conn is a net.Conn, plus a Wait() method.

func WrapUnbufferedConn added in v2.14.1

func WrapUnbufferedConn(inner UnbufferedConn) Conn

type DialerFunc added in v2.9.3

type DialerFunc func(context.Context, string) (net.Conn, error)

type PortForwardDialer added in v2.9.4

type PortForwardDialer interface {
	io.Closer
	Dial(ctx context.Context, addr string) (net.Conn, error)
	DialPod(ctx context.Context, name, namespace string, port uint16) (net.Conn, error)
}

func GetPortForwardDialer added in v2.17.0

func GetPortForwardDialer(ctx context.Context) PortForwardDialer

func NewK8sPortForwardDialer

func NewK8sPortForwardDialer(logCtx context.Context, kubeConfig *rest.Config, k8sInterface kubernetes.Interface) (PortForwardDialer, error)

NewK8sPortForwardDialer returns a dialer function (matching the signature required by grpc.WithContextDialer) that dials to a port on a Kubernetes Pod, in the manor of `kubectl port-forward`. It returns the direct connection to the apiserver; it does not establish a local port being forwarded from or otherwise pump data over the connection.

type UnbufferedConn added in v2.14.1

type UnbufferedConn interface {
	// Receive some data over the connection.
	Recv() ([]byte, error)

	// Send some data over the connection.  Because the connection is fully-synchronous and has
	// no internal buffering, Send must not return until the remote end acknowledges the full
	// transmission (or an error is encountered).
	Send([]byte) error

	// MTU returns the largest amount of data that is permissible to include in a single Send
	// call.
	MTU() int

	// CloseOnce closes both the read-end and write-end of the connection.  Any blocked Recv or
	// Send operations will be unblocked and return errors.  It is an error to call CloseOnce
	// more than once.
	CloseOnce() error

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr
}

UnbufferedConn represents a reliable fully-synchronous stream with *no* internal buffering. But really, what it is is "everything that isn't generic enough to be in bufferedConn".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL