batching

package
v1.92.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package batching implements a socket optimized for increased throughput.

Index

Constants

View Source
const IdealBatchSize = 128

Variables

This section is empty.

Functions

func MinControlMessageSize

func MinControlMessageSize() int

MinControlMessageSize returns the minimum control message size required to support read batching via [Conn.ReadBatch].

func TryUpgradeToConn

func TryUpgradeToConn(pconn nettype.PacketConn, network string, batchSize int) nettype.PacketConn

TryUpgradeToConn probes the capabilities of the OS and pconn, and upgrades pconn to a Conn if appropriate. A batch size of IdealBatchSize is suggested for the best performance.

Types

type Conn

type Conn interface {
	nettype.PacketConn
	// ReadBatch reads messages from [Conn] into msgs. It returns the number of
	// messages the caller should evaluate for nonzero len, as a zero len
	// message may fall on either side of a nonzero.
	//
	// Each [ipv6.Message.OOB] must be sized to at least MinControlMessageSize().
	ReadBatch(msgs []ipv6.Message, flags int) (n int, err error)
	// WriteBatchTo writes buffs to addr.
	//
	// If geneve.VNI.IsSet(), then geneve is encoded into the space preceding
	// offset, and offset must equal [packet.GeneveFixedHeaderLength]. If
	// !geneve.VNI.IsSet() then the space preceding offset is ignored.
	//
	// len(buffs) must be <= batchSize supplied in TryUpgradeToConn().
	//
	// WriteBatchTo may return a [neterror.ErrUDPGSODisabled] error if UDP GSO
	// was disabled as a result of a send error.
	WriteBatchTo(buffs [][]byte, addr netip.AddrPort, geneve packet.GeneveHeader, offset int) error
}

Conn is a nettype.PacketConn that provides batched i/o using platform-specific optimizations, e.g. {recv,send}mmsg & UDP GSO/GRO.

Conn originated from (and is still used by) magicsock where its API was strongly influenced by wireguard-go/conn.Bind constraints, namely wireguard-go's ownership of packet memory.

Jump to

Keyboard shortcuts

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