netpoll

package
v2.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InitPollEventsCap represents the initial capacity of poller event-list.
	InitPollEventsCap = 128
	// MaxPollEventsCap is the maximum limitation of events that the poller can process.
	MaxPollEventsCap = 1024
	// MinPollEventsCap is the minimum limitation of events that the poller can process.
	MinPollEventsCap = 32
	// MaxAsyncTasksAtOneTime is the maximum amount of asynchronous tasks that the event-loop will process at one time.
	MaxAsyncTasksAtOneTime = 256
	// ReadEvents represents readable events that are polled by epoll.
	ReadEvents = unix.EPOLLIN | unix.EPOLLPRI
	// WriteEvents represents writeable events that are polled by epoll.
	WriteEvents = unix.EPOLLOUT
	// ReadWriteEvents represents both readable and writeable events.
	ReadWriteEvents = ReadEvents | WriteEvents
	// ErrEvents represents exceptional events that occurred on the local side.
	ErrEvents = unix.EPOLLERR | unix.EPOLLHUP
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IOEvent

type IOEvent = uint32

IOEvent is the integer type of I/O events on Linux.

type IOFlags added in v2.3.5

type IOFlags = uint16

IOFlags represents the flags of IO events.

type PollAttachment

type PollAttachment struct {
	FD       int
	Callback PollEventHandler
}

PollAttachment is the user data which is about to be stored in "void *ptr" of epoll_data or "void *udata" of kevent.

type PollEventHandler

type PollEventHandler func(int, IOEvent, IOFlags) error

PollEventHandler is the callback for I/O events notified by the poller.

type Poller

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

Poller represents a poller which is in charge of monitoring file-descriptors.

func OpenPoller

func OpenPoller() (poller *Poller, err error)

OpenPoller instantiates a poller.

func (*Poller) AddRead

func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error

AddRead registers the given file-descriptor with readable event to the poller.

func (*Poller) AddReadWrite

func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error

AddReadWrite registers the given file-descriptor with readable and writable events to the poller.

func (*Poller) AddWrite

func (p *Poller) AddWrite(pa *PollAttachment, edgeTriggered bool) error

AddWrite registers the given file-descriptor with writable event to the poller.

func (*Poller) Close

func (p *Poller) Close() error

Close closes the poller.

func (*Poller) Delete

func (p *Poller) Delete(fd int) error

Delete removes the given file-descriptor from the poller.

func (*Poller) ModRead

func (p *Poller) ModRead(pa *PollAttachment, edgeTriggered bool) error

ModRead renews the given file-descriptor with readable event in the poller.

func (*Poller) ModReadWrite

func (p *Poller) ModReadWrite(pa *PollAttachment, edgeTriggered bool) error

ModReadWrite renews the given file-descriptor with readable and writable events in the poller.

func (*Poller) Polling

func (p *Poller) Polling(callback PollEventHandler) error

Polling blocks the current goroutine, waiting for network-events.

func (*Poller) Trigger

func (p *Poller) Trigger(priority queue.EventPriority, fn queue.Func, param any) (err error)

Trigger enqueues task and wakes up the poller to process pending tasks. By default, any incoming task will enqueued into urgentAsyncTaskQueue before the threshold of high-priority events is reached. When it happens, any asks other than high-priority tasks will be shunted to asyncTaskQueue.

Note that asyncTaskQueue is a queue of low-priority whose size may grow large and tasks in it may backlog.

Jump to

Keyboard shortcuts

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