netpoll

package
v2.0.0-rc.150 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 8 Imported by: 1

README

NetPoll

NetPoll is an abstraction of epoll/kqueue for Go.

Its target is implementing a simple epoll lib for network connections, so you should see it only contains few methods about net.Conn. We use epoll in Linux and kqueue in MacOS.

This is a copy of https://github.com/smallnest/epoller (v1.2.0) to remove Windows support and avoid the need for CGO. On Windows, we handle connections in a separate goroutine, without support from the underlying network stack of the operating system.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("epoll/kqueue is not supported on this system")
)

Functions

func SocketFD

func SocketFD(conn net.Conn) int

func Supported

func Supported() error

Supported checks if the more efficient network poll library is functional on the current system. It returns ErrUnsupported error if implementation is not supported. Any other error indicates non-functionality. This function does an integration test of the concrete network implementation to ensure that system calls are working as expected.

Types

type ConnImpl

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

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

func (ConnImpl) GetFD

func (c ConnImpl) GetFD() int

type Epoll

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

EPoll is a poll based connection implementation.

func NewPoller

func NewPoller(connBufferSize int, pollTimeout time.Duration) (*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 and closes it.
	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.

Jump to

Keyboard shortcuts

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