netx

package module
v0.0.0-...-163b162 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 57

Documentation

Overview

Package netx provides additional libraries that extend some of the behaviors in the net standard package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BidiCopy

func BidiCopy(out net.Conn, in net.Conn, bufOut []byte, bufIn []byte) (outErr error, inErr error)

BidiCopy copies between in and out in both directions using the specified buffers, returning the errors from copying to out and copying to in.

func BidiCopyWithOpts

func BidiCopyWithOpts(out net.Conn, in net.Conn, opts *CopyOpts) (outErr <-chan error, inErr <-chan error)

BidiCopyWithOpts is like the original BidiCopy but providing more options and returning channels for reading the errors rather than the errors themselves.

func Dial

func Dial(network string, addr string) (net.Conn, error)

Dial is like DialTimeout using a default timeout of 1 minute.

func DialContext

func DialContext(ctx context.Context, network string, addr string) (net.Conn, error)

DialContext dials the given addr on the given net type using the configured dial function, with the given context.

func DialTimeout

func DialTimeout(network string, addr string, timeout time.Duration) (net.Conn, error)

DialTimeout dials the given addr on the given net type using the configured dial function, timing out after the given timeout.

func DialUDP

func DialUDP(network string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error)

DialUDP acts like Dial but for UDP networks.

func EnableNAT64AutoDiscovery

func EnableNAT64AutoDiscovery()

EnableNAT64 enables automatic discovery of NAT64 prefix using DNS query for ipv4only.arpa. Once enabled, netx will automatically dial IPv4 addresses via IPv6 using this prefix if it is available

func IsTimeout

func IsTimeout(err error) bool

IsTimeout indicates whether the given error is a network timeout error

func ListenUDP

func ListenUDP(network string, laddr *net.UDPAddr) (*net.UDPConn, error)

ListenUDP acts like ListenPacket for UDP networks.

func OverrideDial

func OverrideDial(dialFN func(ctx context.Context, net string, addr string) (net.Conn, error))

OverrideDial overrides the global dial function.

func OverrideDialUDP

func OverrideDialUDP(dialFN func(net string, laddr, raddr *net.UDPAddr) (*net.UDPConn, error))

OverrideDialUDP overrides the global dialUDP function.

func OverrideListenUDP

func OverrideListenUDP(listenFN func(network string, laddr *net.UDPAddr) (*net.UDPConn, error))

OverrideListenUDP overrides the global listenUDP function.

func OverrideResolveIPs

func OverrideResolveIPs(resolveFN func(host string) ([]net.IP, error))

OverrideResolveIPs overrides the global IP resolution function.

func Reset

func Reset()

Reset resets netx to its default settings

func Resolve

func Resolve(network string, addr string) (*net.TCPAddr, error)

Resolve resolves the given tcp address using the configured resolve function.

func ResolveUDPAddr

func ResolveUDPAddr(network string, addr string) (*net.UDPAddr, error)

func WalkWrapped

func WalkWrapped(conn net.Conn, cb func(net.Conn) bool)

WalkWrapped walks the tree of wrapped conns, calling the callback. If callback returns false, the walk stops.

Types

type CopyOpts

type CopyOpts struct {
	BufIn          []byte
	BufOut         []byte
	OnOut          func(int)
	OnIn           func(int)
	StartGoroutine func(func())
}

CopyOpts provides options for BidiCopy. It will use sensible defaults for any missing options

func (*CopyOpts) ApplyDefaults

func (opts *CopyOpts) ApplyDefaults()

type WrappedConn

type WrappedConn interface {
	net.Conn
	Wrapped() net.Conn
}

WrappedConn is a connection that wraps another connection.

Jump to

Keyboard shortcuts

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