epoll

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package epoll implements the epoll-based I/O engine for Linux.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine implements the epoll-based I/O engine.

func New

func New(cfg resource.Config, handler stream.Handler) (*Engine, error)

New creates a new epoll engine.

func (*Engine) Addr

func (e *Engine) Addr() net.Addr

Addr returns the bound listener address.

func (*Engine) Listen

func (e *Engine) Listen(ctx context.Context) error

Listen starts the epoll engine and blocks until context is canceled.

func (*Engine) Metrics

func (e *Engine) Metrics() engine.EngineMetrics

Metrics returns a snapshot of engine metrics.

func (*Engine) NumWorkers added in v1.4.0

func (e *Engine) NumWorkers() int

NumWorkers returns the number of worker event loops. Required by engine.EventLoopProvider.

func (*Engine) PauseAccept added in v0.3.0

func (e *Engine) PauseAccept() error

PauseAccept stops accepting new connections while keeping existing ones alive.

func (*Engine) ResumeAccept added in v0.3.0

func (e *Engine) ResumeAccept() error

ResumeAccept starts accepting new connections again. Wakes any suspended loops so they re-create listen sockets.

func (*Engine) Shutdown

func (e *Engine) Shutdown(_ context.Context) error

Shutdown is a no-op for the epoll engine — graceful shutdown is driven by context cancellation on Listen's parent context. The Server calls Listen with its managed context and cancels it during Server.Shutdown; the Listen goroutine returns after running Loop.shutdown (which closes connections and joins async dispatch goroutines via asyncWG).

The context parameter is accepted for interface parity with engines that do run async drain operations on Shutdown (e.g. std's http.Server.Shutdown), and for future use if epoll Shutdown gains explicit drain semantics.

func (*Engine) Type

func (e *Engine) Type() engine.EngineType

Type returns the engine type.

func (*Engine) WorkerLoop added in v1.4.0

func (e *Engine) WorkerLoop(n int) engine.WorkerLoop

WorkerLoop returns the worker loop at index n. Panics if n is out of range or if the engine has not yet started listening.

type Loop

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

Loop is an epoll-based event loop worker.

func (*Loop) CPUID added in v1.4.0

func (l *Loop) CPUID() int

CPUID returns the CPU the worker is pinned to, or -1 if the worker was not successfully pinned (platform.PinToCPU best-effort).

func (*Loop) RegisterConn added in v1.4.0

func (l *Loop) RegisterConn(fd int, onRecv func([]byte), onClose func(error)) error

RegisterConn adds fd to this worker's epoll interest set and installs the data and close callbacks. fd must already be in non-blocking mode; the caller retains ownership of the fd (UnregisterConn does not close it).

Returns an error if fd is already registered as an HTTP conn on this worker or already registered as a driver conn.

func (*Loop) UnregisterConn added in v1.4.0

func (l *Loop) UnregisterConn(fd int) error

UnregisterConn removes fd from this worker's interest set and schedules the onClose callback (with a nil error) to fire on the next worker iteration. The fd itself is NOT closed — the driver owns its lifetime.

func (*Loop) Write added in v1.4.0

func (l *Loop) Write(fd int, data []byte) error

Write enqueues data for transmission on fd. Returns engine.ErrUnknownFD if fd is not registered on this worker, or engine.ErrQueueFull if the pending backlog would exceed driverWriteCap.

The call is non-blocking: it performs at most one write(2) inline when the socket is idle and otherwise arms EPOLLOUT so the worker flushes the remainder on the next iteration.

Jump to

Keyboard shortcuts

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