workerpool

package
v0.0.0-...-9683c79 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultIdleWorkerDuration = 10 * time.Second

Variables

View Source
var ErrHijacked = xerrors.New("connection has been hijacked")

Functions

This section is empty.

Types

type ConnState

type ConnState int

A ConnState represents the state of a client connection to a server. It's used by the optional Server.ConnState hook.

const (
	// StateNew represents a new connection that is expected to
	// send a request immediately. Connections begin at this
	// state and then transition to either StateActive or
	// StateClosed.
	StateNew ConnState = iota

	// StateActive represents a connection that has read 1 or more
	// bytes of a request. The Server.ConnState hook for
	// StateActive fires before the request has entered a handler
	// and doesn't fire again until the request has been
	// handled. After the request is handled, the state
	// transitions to StateClosed, StateHijacked, or StateIdle.
	// For HTTP/2, StateActive fires on the transition from zero
	// to one active request, and only transitions away once all
	// active requests are complete. That means that ConnState
	// cannot be used to do per-request work; ConnState only notes
	// the overall state of the connection.
	StateActive

	// StateIdle represents a connection that has finished
	// handling a request and is in the keep-alive state, waiting
	// for a new request. Connections transition from StateIdle
	// to either StateActive or StateClosed.
	StateIdle

	// StateHijacked represents a hijacked connection.
	// This is a terminal state. It does not transition to StateClosed.
	StateHijacked

	// StateClosed represents a closed connection.
	// This is a terminal state. Hijacked connections do not
	// transition to StateClosed.
	StateClosed
)

func (ConnState) String

func (c ConnState) String() string

type ServeHandler

type ServeHandler func(c net.Conn) error

ServeHandler must process tls.Config.NextProto negotiated requests.

type WorkerPool

type WorkerPool struct {
	// Function for serving server connections.
	// It must leave c unclosed.
	WorkerFunc ServeHandler

	MaxWorkersCount int

	LogAllErrors bool

	MaxIdleWorkerDuration time.Duration

	Logger logger.Logger

	ConnState func(net.Conn, ConnState)
	// contains filtered or unexported fields
}

WorkerPool serves incoming connections via a pool of workers in FILO order, i.e. the most recently stopped worker will serve the next incoming connection.

Such a scheme keeps CPU caches hot (in theory).

func (*WorkerPool) Serve

func (wp *WorkerPool) Serve(c net.Conn) bool

func (*WorkerPool) Start

func (wp *WorkerPool) Start()

func (*WorkerPool) Stop

func (wp *WorkerPool) Stop()

Jump to

Keyboard shortcuts

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