iface

package
v0.0.0-...-a224364 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

type Bootstrap interface {
	Start() error // 启动服务
	Stop()        // 停止服务

	SetEncoder(encoder encoder.Encoder) // 设置编码器
	GetEncoder() encoder.Encoder        // 获取编码器
	SetDecoder(decoder decoder.Decoder) // 设置解码器
	GetDecoder() decoder.Decoder        // 获取解码器

	AddChannelHandler(handler ChannelHandler) // 添加处理器
	GetChannelHandlers() []ChannelHandler     // 获取处理器

	GetDispatcher() Dispatcher // 获取消息分发器

	SetConnOnActiveFunc(func(conn Connection))  // 设置连接激活的回调函数
	GetConnOnActiveFunc() func(conn Connection) // 获取连接激活的回调函数
	SetConnOnCloseFunc(func(conn Connection))   // 设置连接关闭的回调函数
	GetConnOnCloseFunc() func(conn Connection)  // 获取连接关闭的回调函数
}

Bootstrap 启动器

type ChannelHandler

type ChannelHandler interface {
	PreHandle(ctx Context, msg []byte)   // 预处理
	ChannelRead(ctx Context, msg []byte) // 处理每一帧的数据
	PostHandle(ctx Context, msg []byte)  // 后处理
}

type Client

type Client interface {
	Bootstrap

	GetConfig() *conf.ClientConfig // 获取当前服务的配置

	GetConn() Connection // 获取连接

}

type ConnManager

type ConnManager interface {
	Add(conn Connection)  // 添加连接
	Remove(connId uint32) // 移除连接

	Get(connId uint32) (Connection, bool) // 根据连接id查询连接
	Size() int                            // 获取连接数量

	Clear() // 清理所有连接
}

type Connection

type Connection interface {
	GetConn() net.Conn // 获取连接对象
	GetConnID() uint32 // 获取连接id

	RemoteAddr() net.Addr // 获取远程地址

	Start() // 启动连接,开启读写操作
	Stop()  // 关闭连接,回收资源

	GetPipeline() Pipeline  // 获取当前连接的管道
	Write(msg []byte) error // 向当前连接写入数据

	AddCronFunc(spec string, cmd func()) error
	RemoveCronFunc(id cron.EntryID)
}

type Context

type Context interface {
	context.Context

	GetHandler() ChannelHandler // 获取当前的处理器
	GetConnection() Connection  // 获取连接对象

	DoHandle(msg []byte) // 处理义务逻辑
	FireRead(msg []byte) // 调用下一个handler处理业务
}

type Dispatcher

type Dispatcher interface {
	StartWorkerPool()     // 开启工作协程池
	Dispatch(req Request) // 分发请求到协程池中
}

type Pipeline

type Pipeline interface {
	AddLast(handler ChannelHandler) // 在调用链末尾添加一个连接处理器
	Handle(msg []byte)              // 根据调用链处理消息

	GetConnection() Connection // 获取连接对象
}

type Request

type Request interface {
	GetConn() Connection // 获取本次请求的连接对象
	GetMsg() []byte      // 获取本次请求的消息
}

type Server

type Server interface {
	Bootstrap

	GetConfig() *conf.ServerConfig // 获取当前服务的配置

	GetConnManager() ConnManager // 获取连接管理器
}

Jump to

Keyboard shortcuts

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