reactor

package
v0.0.0-...-69611e8 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRequirements = errors.New("ring does not meet the requirements")

Functions

This section is empty.

Types

type Callback

type Callback func(event uring.CQEvent)

type Logger

type Logger interface {
	Log(keyvals ...interface{})
}

type NetOperation

type NetOperation interface {
	uring.Operation
	Fd() int
}

NetOperation must be implemented by NetworkReactor supported operations.

type NetworkReactor

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

NetworkReactor is event loop's manager with main responsibility - handling client requests and return responses asynchronously. NetworkReactor optimized for network operations like Accept, Recv, Send.

func NewNet

func NewNet(rings []*uring.Ring, opts ...Option) (*NetworkReactor, error)

NewNet create NetworkReactor instance.

func (*NetworkReactor) Cancel

func (r *NetworkReactor) Cancel(id RequestID)

Cancel queued operation. id - SQE id returned by Queue method.

func (*NetworkReactor) Queue

func (r *NetworkReactor) Queue(op NetOperation, cb Callback) RequestID

Queue io_uring operation. Return RequestID which can be used as the SQE identifier.

func (*NetworkReactor) QueueWithDeadline

func (r *NetworkReactor) QueueWithDeadline(op NetOperation, cb Callback, deadline time.Time) RequestID

QueueWithDeadline io_uring operation. After a deadline time, a CQE with the error ECANCELED will be placed in the callback function.

func (*NetworkReactor) Run

func (r *NetworkReactor) Run(ctx context.Context)

Run start NetworkReactor.

type Option

type Option func(cfg *configuration)

func WithLogger

func WithLogger(l Logger) Option

WithLogger set logger for event loop.

func WithTickTimeout

func WithTickTimeout(duration time.Duration) Option

WithTickTimeout set tick duration for event loop.

type Reactor

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

Reactor is event loop's manager with main responsibility - handling client requests and return responses asynchronously.

func New

func New(rings []*uring.Ring, opts ...Option) (*Reactor, error)

New create new reactor instance. rings - io_uring instances. The reactor will create one event loop for each instance. opts - reactor options.

func (*Reactor) Cancel

func (r *Reactor) Cancel(nonce uint64) error

Cancel queued operation. nonce - SQE id returned by Queue method.

func (*Reactor) Queue

func (r *Reactor) Queue(op uring.Operation, cb Callback) (uint64, error)

Queue io_uring operation. Callback function `cb` calling when receive cqe. Return uint64 which can be used as the SQE identifier.

func (*Reactor) QueueWithDeadline

func (r *Reactor) QueueWithDeadline(op uring.Operation, cb Callback, deadline time.Time) (uint64, error)

QueueWithDeadline io_uring operation. Callback function `cb` calling when receive cqe. After a deadline time, a CQE with the error ECANCELED will be placed in the channel retChan.

func (*Reactor) Run

func (r *Reactor) Run(ctx context.Context)

Run start reactor.

type RequestID

type RequestID uint64

RequestID identifier of operation queued into NetworkReactor.

Jump to

Keyboard shortcuts

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