mmsg

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MPL-2.0 Imports: 5 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

github.com/anacrolix/mmsg exposes the batching methods from golang.org/x/net/internal/socket, falling back on OSs that don't implement them.

golang.org/x/net does expose the batching APIs but you have to be explicit about whether you're using ipv4 or ipv6, and IDGAF, it shouldn't be exposed like that.

Message.AddrPort reports the sender as a netip.AddrPort, which costs nothing to produce, so a receive allocates nothing at all, batched or not. Message.Addr is a method rather than a field: it builds a net.Addr from AddrPort the first time it's called, and only callers that want one pay for it.

./socket is taken from golang.org/x/net/internal/socket because we need access to the package and it's internal to golang.org/x/net/internal/socket.
./internal/nettest is taken from golang.org/x/net/nettest. I think because ./socket expects it and we don't want to unnecessarily introduce extra dependencies to golang.org/x/net.

The LICENSE file is taken from golang.org/x/net and put into the respective directories sourced from that module.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn receives datagrams, in batches where the platform can. Its receive methods reuse state held here, so they aren't safe to call concurrently with each other on one Conn.

func NewConn

func NewConn(pr PacketReader) *Conn

pr must implement net.Conn for mmsg to be enabled.

func (*Conn) Err

func (me *Conn) Err() error

Returns not nil if message batching is not working.

func (*Conn) RecvMsg

func (me *Conn) RecvMsg(m *Message) error

func (*Conn) RecvMsgs

func (me *Conn) RecvMsgs(ms []Message) (n int, err error)

type Message

type Message struct {
	Buffers [][]byte
	N       int
	// AddrPort is the sender, and costs nothing to report: a netip.Addr holds its bytes inline.
	// A 4-in-6 address is left mapped, exactly as the kernel reported it. Prefer this to Addr.
	AddrPort netip.AddrPort
	// contains filtered or unexported fields
}

func (*Message) Addr

func (me *Message) Addr() net.Addr

Addr is the sender as a net.Addr, built from AddrPort the first time it's asked for and kept for later calls. Building it allocates the address and the net.IP inside it, which is why receiving no longer does: use AddrPort where it will do.

func (*Message) Payload

func (me *Message) Payload() (p []byte)

type PacketReader

type PacketReader interface {
	ReadFrom([]byte) (int, net.Addr, error)
}

Directories

Path Synopsis
internal
nettest
Package nettest provides utilities for network testing.
Package nettest provides utilities for network testing.
Package socket provides a portable interface for socket system calls.
Package socket provides a portable interface for socket system calls.

Jump to

Keyboard shortcuts

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