iface

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CarryFunc added in v0.1.7

type CarryFunc = func(stack interface{}, item interface{}) interface{}

type IAcceptor

type IAcceptor interface {
	Run(fd int, loop IEventLoop) error
	Exit()
	IncrementID() int
	Close()
}

type IConnect

type IConnect interface {
	Read(bs []byte) (int, error)
	GetFd() int
	GetID() int
	Close() error
	GetPacker() IPacker
	Send(msgID uint32, bs []byte) (int, error)
	GetAddress() net.Addr
	GetEpFd() int
	GetPoller() IPoller
	GetWriteBuff() ([]byte, bool)
	SetLastMessageTime(lastMessageTime time.Time)
	GetLastMessageTime() time.Time
	GetTLSEnable() bool
	GetHandshakeCompleted() bool
	SetHandshakeCompleted()
	GetCertificate() tls.Certificate
	GetTLSLayer() *tls.Conn
	GetConnectMgr() IConnectManager
	Text([]byte) (int, error)   // 发送websocket text数据
	Binary([]byte) (int, error) // 发送 websocket 二进制格式数据
}

type IConnectEvent added in v0.1.3

type IConnectEvent interface {
	DecodePacket() (IMessage, error)
	ProceedWrite() error
	SetState(state common.ConnectState)
	SetWriteBuff([]byte)
	SetEpFd(epfd int)
	SetPoller(poller IPoller)
}

IConnectEvent 专门处理epoll/kqueue事件的方法,无需对外提供

type IConnectManager

type IConnectManager interface {
	Get(connFD int) IConnect
	Add(conn IConnect) int
	GetConnects() []IConnect
	Remove(conn IConnect)
	Len() int
	ClearByEpFd(epfd int)
	ClearAll()
	HeartbeatCheck()
}

type IContext added in v0.1.7

type IContext interface {
	GetRequest() IRequest
	GetConnect() IConnect
	GetMessage() IMessage
	Set(key, value interface{})
	Get(key interface{}) interface{}
}

type IEventLoop

type IEventLoop interface {
	Init(connectMgr IConnectManager) error // 初始化,也就是创建epoll
	Start(messageCh chan<- IContext)       // 开启事件循环,也就是所有的epoll执行epoll_wait
	Stop()                                 // 停止
	AddRead(conn IConnect) error
	Remove(conn IConnect) error
}

IEventLoop 事件循环抽象层,所有的epoll都是通过这个来操作

type IHooks added in v0.0.2

type IHooks interface {
	OnOpen(connect IConnect)
	OnClose(connect IConnect)
}

type IMessage

type IMessage interface {
	ID() uint32
	Bytes() []byte
	String() string
	Len() int
	SetData([]byte)
	GetOpcode() uint8
	IsWebsocket() bool
}

type IMiddlewareGroup added in v0.1.7

type IMiddlewareGroup interface {
	AddRouter(msgID uint32, router IRouter)
	GetMiddlewares() []MiddlewareFunc
	GetRouters() map[uint32]IRouter
}

type IPacker

type IPacker interface {
	Pack(msgID uint32, data []byte) ([]byte, error) // 封包
	UnPack([]byte) (IMessage, error)                // 解包
	SetMaxBodyLength(uint32)                        // 设置包体最大长度限制
	GetHeaderLength() uint32                        // 获取头部长度
}

IPacker 数据封装抽象层

type IPipeline added in v0.1.7

type IPipeline interface {
	Send(passable interface{}) IPipeline
	Pipe(pipe IStage) IPipeline
	Through(pipes []IStage) IPipeline
	Then(destination NextFunc) interface{}
	Carry() CarryFunc
}

type IPoller

type IPoller interface {
	AddRead(fd int, connID int) error
	AddWrite(fd, connID int) error
	ModWrite(fd, connID int) error
	ModRead(fd, connId int) error
	Wait(emitCh chan<- IContext)
	Remove(fd int) error
	Close() error
	GetConnectMgr() IConnectManager
}

type IRequest

type IRequest interface {
	GetConnect() IConnect
	GetMessage() IMessage
	GetConnects() []IConnect
}

type IRouter

type IRouter interface {
	Do(request IRequest)
}

IRouter 路由抽象,根据业务场景实现这个接口即可,通过msgID和router对应

type IServer

type IServer interface {
	Start()
	Stop()
	AddRouter(msgID uint32, router IRouter)
	SetWebSocketHandler(IWebsocketHandler)
}

IServer Server抽象层

type IStage added in v0.1.7

type IStage interface {
	Process(value interface{}, next NextFunc) interface{}
}

type IWebsocketHandler added in v0.1.5

type IWebsocketHandler interface {
	Open(connect IConnect)    // onopen
	Message(request IRequest) // onmessage
	Close(connect IConnect)   // onclose
}

IWebsocketHandler websocket协议相关回调

type MiddlewareFunc added in v0.1.7

type MiddlewareFunc = func(ctx IContext, next Next) interface{}

type Next added in v0.1.7

type Next = func(ctx IContext) interface{}

type NextFunc added in v0.1.7

type NextFunc = func(value interface{}) interface{}

type PipeFunc added in v0.1.7

type PipeFunc = func(passable interface{}) interface{}

Jump to

Keyboard shortcuts

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