net

package
v0.0.0-...-d8f7d12 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InterfaceTypeBonding = 1 << iota
	InterfaceTypeBridge
	InterfaceTypeEtherNet
	InterfaceTypeVlan
	InterfaceTypeTunTap
)
View Source
const SO_REUSEPORT = 15

Variables

This section is empty.

Functions

func BindAndDial

func BindAndDial(network, localAddr, remoteAddr string, timeout time.Duration) (
	net.Conn, error)

BindAndDial is similar to the net.Dial function from the standard library except it binds the underlying network socket to a specified local address. This gives control over the local port number of the connection, rather than a randomly assigned port number.

func CreateTapDevice

func CreateTapDevice() (*os.File, string, error)

CreateTapDevice will create a "tap" network device with a randomly chosen interface name. The tap device file and the interface name are returned on success, else an error is returned. The device will be destroyed when the file is closed.

func GetBridgeVlanId

func GetBridgeVlanId(bridgeIf string) (int, error)

GetBridgeVlanId will get the VLAN Id associated with the uplink EtherNet interface for the specified bridge interface. If there is no uplink then the returned VLAN Id will be -1.

func ListBridges

func ListBridges() ([]net.Interface, error)

ListBridges will return a list of EtherNet (layer 2) bridges.

func ListBroadcastInterfaces

func ListBroadcastInterfaces(interfaceType uint, logger log.DebugLogger) (
	[]net.Interface, map[string]net.Interface, error)

ListBroadcastInterfaces will return a list of broadcast (EtherNet, bridge, vlan) interfaces. Debugging progress messages are logged to logger.

func ListenWithReuse

func ListenWithReuse(network, address string) (net.Listener, error)

ListenWithReuse is similar to the net.Listen function from the standard library but sets the SO_REUSEADDR and SO_REUSEPORT options on the underlying socket. This is needed if using BindAndDial to specify the same local address as with the listener.

func TestCarrier

func TestCarrier(name string) bool

TestCarrier will return true if the interface has a carrier signal.

Types

type CpuSharer

type CpuSharer interface {
	GrabCpu()
	ReleaseCpu()
}

CpuSharer defines the interface for types which can be used to co-operatively share CPUs.

type Dialer

type Dialer interface {
	Dial(network, address string) (net.Conn, error)
}

Dialer defines a dialer that can be use to create connections.

func NewCpuSharingDialer

func NewCpuSharingDialer(dialer Dialer, cpuSharer CpuSharer) Dialer

NewCpuSharingDialer wraps dialer and returns a new Dialer which uses the cpuSharer to limit concurrent CPU usage. Whenever a blocking operation is about to commence (such a Dial or Read or Write for the connection) the cpuSharer.ReleaseCpu method is called, allowing the blocking operation to run concurrently. When the blocking operation completes, the cpuSharer.GrabCpu method is called, limiting the number of running goroutines that have to compete for the CPU. This helps avoid the thundering herd problem where large numbers of goroutines processing network transactions overwhelm the CPU and affect the responsiveness of other goroutines such as dashboards and health checks.

type MeasuringConnection

type MeasuringConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

MeasuringConnection implements the net.Conn interface. Additionally it has methods to return the cumulative time spent blocking in the Read or Write methods.

func (*MeasuringConnection) CumulativeReadTime

func (conn *MeasuringConnection) CumulativeReadTime() time.Duration

CumulativeReadTime returns the cumulative time spent blocking on Read.

func (*MeasuringConnection) CumulativeWriteTime

func (conn *MeasuringConnection) CumulativeWriteTime() time.Duration

CumulativeReadTime returns the cumulative time spent blocking on Write.

func (*MeasuringConnection) Read

func (conn *MeasuringConnection) Read(b []byte) (n int, err error)

func (*MeasuringConnection) Write

func (conn *MeasuringConnection) Write(b []byte) (n int, err error)

type MeasuringDialer

type MeasuringDialer struct {
	// contains filtered or unexported fields
}

MeasuringDialer implements the Dialer interface. Additionally it has methods to return the cumulative time spent blocking in the Dial method.

func NewMeasuringDialer

func NewMeasuringDialer(dialer Dialer) *MeasuringDialer

NewMeasuringDialer wraps dialer and returns a dialer that can be used to measure the time spent in blocking operations.

func (*MeasuringDialer) CumulativeDialTime

func (d *MeasuringDialer) CumulativeDialTime() time.Duration

CumulativeDialTime returns the cumulative time spent blocking on Dial.

func (*MeasuringDialer) Dial

func (d *MeasuringDialer) Dial(network, address string) (net.Conn, error)

type TCPConn

type TCPConn interface {
	net.Conn
	SetKeepAlive(keepalive bool) error
	SetKeepAlivePeriod(d time.Duration) error
}

Directories

Path Synopsis
Package rrdialer implements a dialer which provides improved behaviour for hostnames with multiple IP addresses (aka.
Package rrdialer implements a dialer which provides improved behaviour for hostnames with multiple IP addresses (aka.
terminal

Jump to

Keyboard shortcuts

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