gnet

package module
v0.0.0-...-214a605 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2019 License: MIT Imports: 18 Imported by: 5

README

gnet

Build Status Go Report Card MIT licensed GoDoc

install

go get -u github.com/MaxnSter/gnet

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithMeta

func WithMeta(m meta.Meta) func(Operator)

func WithReadHooks

func WithReadHooks(i ReadInterceptor) func(Operator)

func WithWriteHooks

func WithWriteHooks(i WriteInterceptor) func(Operator)

Types

type Callback

type Callback struct {
	OnSession     func(NetSession)
	OnMessage     func(Event)
	OnSessionStop func(NetSession)
}

type Event

type Event interface {
	// Session返回本条消息对应的NetSession
	Session() NetSession

	// Message返回经过unPack,decode之后的消息
	Message() interface{}
}

Event 是onMessage回调中传入的参数

type Module

type Module interface {
	Pool() pool.Pool
	Coder() codec.Coder
	Packer() packer.Packer
}

Module 是gnet的所有组件集合

func NewModule

func NewModule(pool pool.Pool, c codec.Coder, packer packer.Packer) Module

type NetClient

type NetClient interface {
	SessionManager
	Runner
}

func NewClient

func NewClient(conn net.Conn, m Module, o Operator) NetClient

type NetServer

type NetServer interface {
	SessionManager
	Runner
}

func NewServer

func NewServer(l net.Listener, m Module, o Operator) NetServer

type NetSession

type NetSession interface {
	ID() uint64
	LocalAddr() net.Addr
	RemoteAddr() net.Addr

	Send(message interface{})
	AccessManager() SessionManager

	Runner
}

type Operator

type Operator interface {
	PostEvent(ev Event)
	Read(reader io.Reader) (interface{}, error)
	Write(writer io.Writer, msg interface{}) error

	GetCallback() Callback
}

func NewOperator

func NewOperator(m Module, cb Callback, opts ...func(Operator)) Operator

type ReadInterceptor

type ReadInterceptor struct {
	PreRead  func(r io.Reader, m meta.Meta) (io.Reader, meta.Meta)
	InRead   func(buf []byte, m meta.Meta) ([]byte, meta.Meta)
	PostRead func(msg interface{}) interface{}
}

type Runner

type Runner interface {
	Run()
	Stop()
}

type SessionManager

type SessionManager interface {
	// BroadCast对所有NetSession连接执行fn
	// 若module设置Pool,则fn全部投入Pool中,否则在当前goroutine执行
	Broadcast(func(session NetSession))

	// GetSession返回指定id对应的NetSession
	GetSession(id uint64) (NetSession, bool)
}

type WriteInterceptor

type WriteInterceptor struct {
	PreWrite func(w io.Writer, msg interface{}) (io.Writer, interface{})
	InWrite  func(w io.Writer, buf []byte) (io.Writer, []byte)
}

Jump to

Keyboard shortcuts

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