Documentation
¶
Overview ¶
Package netx contains types to describe and abstract over how dialing and listening are performed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RaceDial ¶ added in v1.100.0
func RaceDial(ctx context.Context, addrs []netip.AddrPort, dial DialFunc, fallbackDelay time.Duration) (net.Conn, error)
RaceDial races TCP connect attempts across addrs using a happy-eyeballs-style staggered approach: a new dial is started every fallbackDelay, and the first successful connection wins. Losers are cancelled and their connections closed. If all dials fail, the first error is returned.
Addresses are interleaved v6-first so that IPv6 is preferred but both families are tried promptly. The dial func is always called with network "tcp".
Types ¶
type DialFunc ¶
DialFunc is a function that dials a network address.
It's the type implemented by net.Dialer.DialContext or required by net/http.Transport.DialContext, etc.
type Network ¶
type Network interface {
NewLocalTCPListener() net.Listener
Listen(network, address string) (net.Listener, error)
Dial(ctx context.Context, network, address string) (net.Conn, error)
}
Network describes a network that can listen and dial. The two common implementations are RealNetwork, using the net package to use the real network, or [memnet.Network], using an in-memory network (typically for testing)
func RealNetwork ¶
func RealNetwork() Network
RealNetwork returns a Network implementation that uses the real net package.