evnio

package module
v0.0.0-...-6a24336 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 11 Imported by: 0

README

evnio

A lightweight, fast non-blocking TCP network library based on Reactor mode.

Feature

  • fast and simple
  • low memory usage
  • cross-platform

Getting Started

Install

go get -u github.com/dreamans/evnio

Websocket example

https://github.com/dreamans/evnio/tree/master/examples/websocket

License

MIT

Documentation

Index

Constants

View Source
const (
	ConnectFdContextKey = "connect-fd-context-key"
)

Variables

View Source
var ErrConnectionClosed = errors.New("connection closed")
View Source
var ErrServerClosed = errors.New("evnio: Server closed")

Functions

func NewBufferPoll

func NewBufferPoll() (pool sync.Pool)

Types

type Action

type Action uint8
const (
	ActionNone Action = iota
	ActionClose
)

type Connection

type Connection interface {
	UniqID() uint64

	RemoteAddr() net.Addr

	LocalAddr() net.Addr

	Context() context.Context

	SetContext(context.Context)

	Send([]byte, Action) error

	Close() error
}

type ConnectionHandler

type ConnectionHandler interface {
	OnOpen(c Connection)
	OnMessage(c Connection, data []byte)
	OnClose(c Connection)
}

type EventHandler

type EventHandler interface {
	EventHandler(fd int, events poller.Event)
	Close() error
}

type EventLoop

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

func (*EventLoop) AddFdHandler

func (ev *EventLoop) AddFdHandler(fd int, handler EventHandler) error

func (*EventLoop) DelFdHandler

func (ev *EventLoop) DelFdHandler(fd int) error

func (*EventLoop) EnableRead

func (ev *EventLoop) EnableRead(fd int) error

func (*EventLoop) EnableReadWrite

func (ev *EventLoop) EnableReadWrite(fd int) error

func (*EventLoop) PacketBuf

func (ev *EventLoop) PacketBuf() []byte

func (*EventLoop) Stop

func (ev *EventLoop) Stop() error

func (*EventLoop) Trigger

func (ev *EventLoop) Trigger(fn func())

func (*EventLoop) Wait

func (ev *EventLoop) Wait()

type ListenHandler

type ListenHandler func(ncfd int, sa syscall.Sockaddr)

type Listener

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

func NewListener

func NewListener(addr string, evLoop *EventLoop, handler ListenHandler) (*Listener, error)

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) EventHandler

func (l *Listener) EventHandler(fd int, events poller.Event)

func (*Listener) Fd

func (l *Listener) Fd() int

type Options

type Options struct {
	Addr     string
	NumLoops int
	Protocol Protocol
	Handler  ConnectionHandler
}

func NewOptions

func NewOptions() *Options

func (*Options) SetAddr

func (opts *Options) SetAddr(addr string) *Options

func (*Options) SetHandler

func (opts *Options) SetHandler(handler ConnectionHandler) *Options

func (*Options) SetNumLoops

func (opts *Options) SetNumLoops(num int) *Options

func (*Options) SetProtocol

func (opts *Options) SetProtocol(protocol Protocol) *Options

type Protocol

type Protocol interface {
	UnPacket(Connection, *bytes.Buffer) []byte
	Packet(Connection, []byte) []byte
}

type Server

type Server interface {
	Start() error
	Shutdown() error
}

func NewServer

func NewServer(opt *Options) Server

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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