epoller

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: MIT Imports: 5 Imported by: 9

README

epoller

epoll implementation for connections in Linux, MacOS and Windows.

License GoDoc github actions Go Report Card coveralls

Its target is implementing a simple epoll lib for nework connections, so you should see it only contains few methods about net.Conn:

type Poller interface {
	// Add adds an existed connection to poller.
	Add(conn net.Conn) error
	// Remove removes a connection from poller. Notice it doesn't call the conn.Close method.
	Remove(conn net.Conn) error
	// Wait waits for at most count events and returns the connections.
	Wait(count int) ([]net.Conn, error)
	// Close closes the poller. If closeConns is true, it will close all the connections.
	Close(closeConns bool) error
}

Inspired by 1m-go-websockets.

Contributors

see contributors.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnImpl added in v1.1.0

type ConnImpl struct {
	net.Conn
	// contains filtered or unexported fields
}

ConnImpl is a net.Conn with GetFD() method.

func (ConnImpl) GetFD added in v1.1.0

func (c ConnImpl) GetFD() int

type Epoll

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

Epoll is a epoll based poller.

func NewPoller

func NewPoller(connBufferSize int) (*Epoll, error)

NewPoller creates a new epoll poller.

func (*Epoll) Add

func (e *Epoll) Add(conn net.Conn) error

Add adds a connection to the poller.

func (*Epoll) Close

func (e *Epoll) Close(closeConns bool) error

Close closes the poller. If closeConns is true, it will close all the connections.

func (*Epoll) Remove

func (e *Epoll) Remove(conn net.Conn) error

Remove removes a connection from the poller.

func (*Epoll) Wait

func (e *Epoll) Wait(count int) ([]net.Conn, error)

Wait waits for at most count events and returns the connections.

type Poller

type Poller interface {
	// Add adds the connection to poller.
	Add(conn net.Conn) error
	// Remove removes the connection from poller. Notice it doesn't call the conn.Close method.
	Remove(conn net.Conn) error
	// Wait waits for at most count events and returns the connections.
	Wait(count int) ([]net.Conn, error)
	// Close closes the poller. If closeConns is true, it will close all the connections.
	Close(closeConns bool) error
}

Poller is the interface for epoll/kqueue poller, special for network connections.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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