iomultiplexer

package
v0.0.0-...-9473d91 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMaxClients is returned when the maxClients is less than 0
	ErrInvalidMaxClients = errors.New("invalid max clients")
)

Functions

This section is empty.

Types

type Epoll

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

Epoll implements the IOMultiplexer interface for Linux-based systems

func New

func New(maxClients int) (*Epoll, error)

New creates a new Epoll instance

func (*Epoll) Close

func (ep *Epoll) Close() error

Close closes the Epoll instance

func (*Epoll) Poll

func (ep *Epoll) Poll(timeout time.Duration) ([]Event, error)

Poll polls for all the subscribed events simultaneously and returns all the events that were triggered It blocks until at least one event is triggered or the timeout is reached

func (*Epoll) Subscribe

func (ep *Epoll) Subscribe(event Event) error

Subscribe subscribes to the given event

type Event

type Event struct {
	// Fd denotes the file descriptor
	Fd int
	// Op denotes the operations on file descriptor that are to be monitored
	Op Operations
}

Event is a platform independent representation of a subscribe event For linux platform, this is translated to syscall.EpollEvent For darwin platform, this is translated to syscall.Kevent_t

type IOMultiplexer

type IOMultiplexer interface {
	// Subscribe subscribes to the given event
	// When the event is triggered, the Poll method will return it
	Subscribe(event Event) error

	// Poll polls for all the subscribed events simultaneously
	// and returns all the events that were triggered
	// It blocks until at least one event is triggered or the timeout is reached
	Poll(timeout time.Duration) ([]Event, error)

	// Close closes the IOMultiplexer instance
	Close() error
}

IOMultiplexer defines a generic interface for platform-specific I/O multiplexer implementations

type Operations

type Operations uint32

Operations is a platform independent representation of the operations that need to be monitored on a file descriptor

const (
	// OP_READ represents the read operation
	OP_READ Operations = 1 << iota
	// OP_WRITE represents the write operation
	OP_WRITE
)

Jump to

Keyboard shortcuts

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