Version: v0.6.0 Latest Latest

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

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



Package conn implements underlay sockets with additional metadata on reads.



View Source
const ReceiveBufferSize = 1 << 20

ReceiveBufferSize is the default size, in bytes, of receive buffers for opened sockets.


This section is empty.


This section is empty.


type Config

type Config struct {
	// ReceiveBufferSize is the size of the operating system receive buffer, in
	// bytes. If 0, the package constant is used instead.
	ReceiveBufferSize int

Config customizes the behavior of an underlay socket.

type Conn

type Conn interface {
	Read(common.RawBytes) (int, *ReadMeta, error)
	ReadBatch(Messages, []ReadMeta) (int, error)
	Write(common.RawBytes) (int, error)
	WriteTo(common.RawBytes, *net.UDPAddr) (int, error)
	WriteBatch(Messages) (int, error)
	LocalAddr() *net.UDPAddr
	RemoteAddr() *net.UDPAddr
	SetReadDeadline(time.Time) error
	SetWriteDeadline(time.Time) error
	SetDeadline(time.Time) error
	Close() error

Conn describes the API for an underlay socket with additional metadata on reads.

func New

func New(listen, remote *net.UDPAddr, cfg *Config) (Conn, error)

New opens a new underlay socket on the specified addresses.

The config can be used to customize socket behavior. If config is nil, default values are used.

type Messages

type Messages []ipv4.Message

Messages is a list of ipX.Messages. It is necessary to hide the type alias between ipv4.Message, ipv6.Message and socket.Message.

func NewReadMessages

func NewReadMessages(n int) Messages

NewReadMessages allocates memory for reading IPv4 Linux network stack messages.

func NewWriteMessages

func NewWriteMessages(n int) Messages

NewWriteMessages allocates memory for writing IPv4 Linux network stack messages.

type ReadMeta

type ReadMeta struct {
	// Src is the remote address from which the datagram was received
	Src *net.UDPAddr
	// Local is the address on which the datagram was received
	Local *net.UDPAddr
	// RcvOvfl is the total number of packets that were dropped by the OS due
	// to the receive buffers being full.
	RcvOvfl uint32
	// Recvd is the timestamp when the kernel placed the packet in the socket's
	// receive buffer. N.B. this is in system time, it is _not_ monotonic.
	Recvd time.Time
	// ReadDelay is the time elapsed between the kernel adding a packet to the
	// socket's receive buffer, and the application reading it from the Go
	// network stack (i.e., kernel to application latency).
	ReadDelay time.Duration

ReadMeta contains extra information about socket reads.

Source Files


Path Synopsis
Package mock_conn is a generated GoMock package.
Package mock_conn is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL