Documentation
¶
Overview ¶
Package epoll implements the epoll-based I/O engine for Linux.
Index ¶
- type Engine
- func (e *Engine) Addr() net.Addr
- func (e *Engine) Listen(ctx context.Context) error
- func (e *Engine) Metrics() engine.EngineMetrics
- func (e *Engine) NumWorkers() int
- func (e *Engine) PauseAccept() error
- func (e *Engine) PauseWorker(i int)
- func (e *Engine) ResumeAccept() error
- func (e *Engine) ResumeWorker(i int)
- func (e *Engine) Shutdown(_ context.Context) error
- func (e *Engine) Type() engine.EngineType
- func (e *Engine) WorkerLoop(n int) engine.WorkerLoop
- type Loop
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 (*Engine) Metrics ¶
func (e *Engine) Metrics() engine.EngineMetrics
Metrics returns a snapshot of engine metrics.
func (*Engine) NumWorkers ¶ added in v1.4.0
NumWorkers returns the number of worker event loops. Required by engine.EventLoopProvider.
func (*Engine) PauseAccept ¶ added in v0.3.0
PauseAccept stops accepting new connections. Synchronous — blocks until every loop has closed its listen FD (and drained pending accepts in the kernel queue with FIN, not RST). The adaptive engine relies on this: until the standby's listen sockets are gone from the SO_REUSEPORT routing pool, fresh dials may land on the about-to-pause engine and get RST'd when its FD closes. Synchronous Pause means callers can expose Addr() knowing only the active engine listens.
func (*Engine) PauseWorker ¶ added in v1.4.1
PauseWorker deactivates loop i. The loop drains in-flight conns and goes SUSPENDED. Asynchronous; returns immediately.
func (*Engine) ResumeAccept ¶ added in v0.3.0
ResumeAccept starts accepting new connections again. Wakes any suspended loops so they re-create listen sockets.
func (*Engine) ResumeWorker ¶ added in v1.4.1
ResumeWorker reactivates loop i. Wakes the loop from SUSPENDED if it was already idle.
func (*Engine) Shutdown ¶
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) WorkerLoop ¶ added in v1.4.0
func (e *Engine) WorkerLoop(n int) engine.WorkerLoop
WorkerLoop returns the worker loop at index n. Out-of-range n is reduced modulo NumWorkers so callers can hash a connection / FD across the available pool without first reading NumWorkers. Negative n is mirrored to the positive side. Panics only when the engine has no loops (i.e. Listen has not yet started).
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
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
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
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
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.