evio

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 5 Imported by: 0

README

evio
Build Status GoDoc

evio-lite is an event loop networking framework that is extra small and fast. It's the lite version of the evio package.

So what's different about this version?

It's totally single-threaded. The big evio has support for spreading loops over threads. Not this one. Only one thread. Don't question my motives. I don't care about your feelings on the matter. Also it only runs on BSD and Linux machines. These are the only machines I deal with. Again, I don't care what you say.

There are a few subtle differences between the two APIs, but otherwise they work in the same.

Enjoy! (or not, whatever)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(events Events, addr ...string) error

Serve ...

Types

type Action

type Action int

Action that occurs after the completion of an event.

const (
	// None indicates that no action should occur following an event.
	None Action = iota
	// Close the connection.
	Close
	// Shutdown the server.
	Shutdown
)

type Conn

type Conn interface {
	// Context returns a user-defined context.
	Context() interface{}
	// SetContext sets a user-defined context.
	SetContext(interface{})
	// AddrIndex is the index of server addr that was passed to the Serve call.
	AddrIndex() int
	// LocalAddr is the connection's local socket address.
	LocalAddr() net.Addr
	// RemoteAddr is the connection's remote peer address.
	RemoteAddr() net.Addr
	// Write data to connection.
	Write(data []byte)
	// Close the connection.
	Close()
}

Conn ...

type Events

type Events struct {
	// Serving fires when the server can accept connections. The server
	// parameter has information and various utilities.
	Serving func(server Server) (action Action)
	// Opened fires when a new connection has opened.
	// The info parameter has information about the connection such as
	// it's local and remote address.
	// Use the out return value to write data to the connection.
	Opened func(c Conn) (out []byte, action Action)
	// Closed fires when a connection has closed.
	// The err parameter is the last known connection error.
	Closed func(c Conn) (action Action)
	// PreWrite fires just before any data is written to any client socket.
	PreWrite func()
	// Data fires when a connection sends the server data.
	// The in parameter is the incoming data.
	// Use the out return value to write data to the connection.
	Data func(c Conn, in []byte) (out []byte, action Action)
	// Tick fires immediately after the server starts and will fire again
	// following the duration specified by the delay return value.
	Tick func(now time.Time) (delay time.Duration, action Action)
}

Events ...

type Server

type Server struct {
	// The addrs parameter is an array of listening addresses that align
	// with the addr strings passed to the Serve function.
	Addrs []net.Addr
}

Server ...

Jump to

Keyboard shortcuts

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