Miface

package
v0.0.0-...-2ea0082 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BangdinFunc

type BangdinFunc func(*net.TCPConn, []byte, int) error

type IConnManager

type IConnManager interface {
	// 增加连接
	ConnManAdd(Iconnect) error
	// 删除连接
	ConnManDel(Iconnect)
	// 中断所有的连接
	ConnManDelAll()
	// 根据连接ID获取连接
	ConnManGetID(int) Iconnect
	// 获取当前总连接数量
	ConnManGetNum() int
}

用于定义控制连接connManager的接口

type IMsgHandle

type IMsgHandle interface {
	// 调度路由Router方法
	RouterUse(request Irequest) error
	// 添加路由Router方法
	RouterAdd(msgid uint64, router IRouter) error
	// 创建工作池队列的方法
	StartWorkPool()
	// 将收到的request发送给对应的工作池 并做简易负载均衡
	SendRequestToWorkPool(request Irequest)
}

定义Message的路由管理模块MsgHandle的抽象层接口

type IPack

type IPack interface {
	// 获取包头部的长度
	GetPackLen(Imessage) uint64
	// 打包
	Pack(Imessage) ([]byte, error)
	// 解包
	UnPack([]byte) (Imessage, error)
}

用于定义接受数据的打包方法msgpack的抽象层

type IRouter

type IRouter interface {
	// 处理业务前
	HandleQian(request Irequest)
	// 处理业务
	Handle(request Irequest)
	// 处理业务后
	HandleHou(request Irequest)
}

用于定义路由irouter的抽象接口层

type Iconnect

type Iconnect interface {
	// 启动 让连接开始工作
	Start()
	// 停止 结束当前连接的工作
	Stop()
	// 获取绑定的连接接口
	Getconn() *net.TCPConn
	// 获取连接的ID
	GetConnID() int64
	// 获取连接的状态属性 IP 端口等
	GetconnInfo() net.Addr
	// 发送数据 使用连接将数据发送给客户端
	SendMsg(msg []byte) error
	// 提供一个发送Message的方法
	SendPackMsg(sendID uint64, sendData []byte) error
	// 添加属性
	InfoAdd(string, interface{})
	// 删除属性
	InfoDel(string)
	// 查询属性
	InfoFind(string) interface{}
}

定义 连接的接口

type Imessage

type Imessage interface {

	// 获取消息的长度
	GetLen() uint64
	// 获取消息的ID
	GetID() uint64
	// 获取消息的内容
	GetMsg() []byte

	// 设置消息的ID
	SetMsgID(uint64)
	// 设置消息的内容
	SetMsg([]byte)
}

用于定义消息的抽象接口层

type Irequest

type Irequest interface {
	GetConnect() Iconnect
	GetData() []byte
	GetID() uint64
	GetLen() uint64
}

定义request请求接口

type MServer

type MServer interface {
	// 启动
	Start()
	// 停止
	Stop()
	// 运行
	Run()
	// 添加一个新路由
	AddNewRouter(addid uint64, router IRouter)
	// 返回服务器所拥有的连接池
	GetServerConnManager() IConnManager
}

Jump to

Keyboard shortcuts

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