loop

package
v0.26.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package loop is the network domain's event-loop engine (ADR 0186): the native backends a plaintext stream group runs on when it is served by a corenet.LoopHandler — epoll on every Linux architecture, io_uring after a staged probe of the running kernel — and nothing else of the SDK.

It is a leaf below server (§D3): it imports internal/core/net, the shared UnsupportedPlatform of internal/core/proc and the kernel, never server. server binds or adopts the listeners, keeps the lifecycle, the admission and the drain, and hands the loop duplicated descriptors through one type, Listener. The portable backend stays in server: it needs the netpoller.

A loop is one goroutine locked to its OS thread, owning its rings or its epoll instance. Its connection table is pointer-free Go memory the race detector sees; every byte the kernel reads or writes — the read arena, the spill and output slab — is mapped outside the Go heap (§D7). The engine knows bytes, references, deadlines, write pressure and the order of writes; it speaks no HTTP.

An idle connection on a native backend costs at most 256 bytes of Go heap — its slot and its timer link — and no mapped byte: its output chunk is attached at its first Write and returned once drained.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Group is the group's name, for the start line and State.
	Group string
	// Value is the group's LoopValue.
	Value corenet.LoopValue
	// MaxConns is LimitsValue.MaxConns: past it a connection is accepted and
	// closed at once. Zero sets no ceiling.
	MaxConns int
	// IdleTimeout closes a connection with no traffic for that long, its
	// output sent. Zero sets none.
	IdleTimeout time.Duration
	// Handler is the group's loop handler.
	Handler corenet.LoopHandler
	// Listeners are the sockets to accept on.
	Listeners []Listener
	// Log receives the one start line; nil is standard error.
	Log io.Writer
	// contains filtered or unexported fields
}

Config is what server gives a loop group to start: the group's name, its LoopValue, the two options the engine honours itself — MaxConns and IdleTimeout — its handler and its listeners.

type Group

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

Group is a running loop group: its loops, their threads and their rings. Start is the one way to get one, so a Group always runs, or ran and was stopped by Shutdown or Close.

func Start

func Start(cfg Config) (*Group, error)

Start resolves cfg against the effective RLIMIT_NOFILE — refusing with LoopNoDescriptors when it is zero or unreadable, before the one ring formula divides by it — starts the group's loops on the backend cfg asks for, and writes one line to cfg.Log naming the backend, the probe stage, any fallback reason, the loops, the rings and their sizes. The listeners are the group's from the call on, started or refused. An explicit backend the platform has no mechanic for is UnsupportedPlatform; one the kernel's probe refused is LoopBackendUnavailable.

func (*Group) Close

func (g *Group) Close() error

Close closes every connection and stops every loop now.

func (*Group) Live

func (g *Group) Live() int64

Live is how many connections the group serves now.

func (*Group) Rejected

func (g *Group) Rejected() uint64

Rejected is how many connections MaxConns turned away.

func (*Group) Shutdown

func (g *Group) Shutdown(ctx context.Context) error

Shutdown stops accepting and waits for every connection to settle, its output sent, until ctx is done; then it closes the rest. A drain cut short returns DrainTimeout.

func (*Group) State

func (g *Group) State() corenet.LoopStateValue

State reports the group's backend and every ring's counters.

type Listener

type Listener struct {
	// FD is the duplicated descriptor, close-on-exec.
	FD int
}

Listener is the one hand-off from server to the loop: a listening socket server has already bound or adopted, as a duplicated descriptor the loop group owns from then on and closes when it stops.

Jump to

Keyboard shortcuts

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