ziface

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: AFL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandleFunc

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

HandleFunc 定义一个处理连接业务的方法

type IConnManager

type IConnManager interface {
	// AddConn 添加连接
	AddConn(conn IConnection)
	// RemoveConn 删除连接
	RemoveConn(conn IConnection)
	// GetConn 根据connID获取连接
	GetConn(connID uint32) (IConnection, error)
	// GetConnCount	得到当前连接总数
	GetConnCount() int
	// ClearConn 清理并终止所有的连接
	ClearConn()
}

type IConnection

type IConnection interface {
	// Start 启动连接 让当前的连接准备开始工作
	Start()

	// Stop 停止连接 结束当前连接的工作
	Stop()

	// GetTcpConnection 获取当前连接的绑定的socket conn
	GetTcpConnection() *net.TCPConn

	// GetConnID 获取当前连接模块的连接ID
	GetConnID() uint32

	// RemoteAddr 获取远程客户端的 TCP状态 IP port
	RemoteAddr() net.Addr

	// SendMsg 发送消息, 将数据发送给远程的客户端
	SendMsg(msgId uint32, data []byte) error

	// SetProperty 设置连接属性
	SetProperty(key string, value interface{})
	// GetProperty 获取连接属性
	GetProperty(key string) (interface{}, error)
	// RemoveProperty 删除连接属性
	RemoveProperty(key string)
}

IConnection 定义连接模块的抽象层

type IDataPacket

type IDataPacket interface {
	// GetHeadLen 获取包的头的长度方法
	GetHeadLen() uint32
	// Pack 封包方法
	Pack(msg IMessage) ([]byte, error)
	// UnPack 拆包方法
	UnPack(data []byte) (IMessage, error)
}

type IMessage

type IMessage interface {
	// GetMsgId 获取消息的ID
	GetMsgId() uint32
	// SetMsgId 设置消息的ID
	SetMsgId(uint32)
	// GetMsgBody 获取消息体
	GetMsgBody() []byte
	// SetMsgBody 设置消息体
	SetMsgBody([]byte)
	// GetMsgBodyLen 获取消息体长度
	GetMsgBodyLen() uint32
	// SetMsgBodyLen 设置消息体长度
	SetMsgBodyLen(uint32)
}

type IMsgHandler

type IMsgHandler interface {
	// DoMsgHandler 调度/执行对应的Router消息处理方法
	DoMsgHandler(request IRequest)
	// AddRouter 为消息添加具体的处理逻辑
	AddRouter(msgId uint32, router IRouter)
	// StartWorkerPool 启动Worker工作池
	StartWorkerPool()
	// SendMsgToTaskQueue 将消息交给TaskQueue, 由Worker进行管理
	SendMsgToTaskQueue(request IRequest)
}

type IRequest

type IRequest interface {
	// GetConnection 得到当前连接
	GetConnection() IConnection

	// GetMessageBody 获取消息数据
	GetMessageBody() []byte

	// GetMessageID 获取消息的ID
	GetMessageID() uint32

	// GetMessageLen 获得消息的长度
	GetMessageLen() uint32
}

type IRouter

type IRouter interface {
	// PreHandle 在处理conn业务之前的钩子方法Hook
	PreHandle(request IRequest)
	// Handle 在处理conn业务的主方法hook
	Handle(request IRequest)
	// PostHandle 在处理conn业务之后的钩子方法Hook
	PostHandle(request IRequest)
}

type IServer

type IServer interface {
	// Start 启动服务器
	Start()
	// Stop 停止服务器
	Stop()
	// Run 运行服务器
	Run()
	// AddRouter 路由功能:给当前的服务注册一个路由方法;供客户端的连接处理使用
	AddRouter(msgID uint32, router IRouter)
	// GetConnMgr 获取当前Server的ConnMgr
	GetConnMgr() IConnManager
	// GetMsgHandler 获取当前Server的ConnMgr
	GetMsgHandler() IMsgHandler
	// SetOnConnStart 注册OnConnStar 钩子函数的方法
	SetOnConnStart(f func(connection IConnection))
	// CallOnConnStart 调用OnConnStart 钩子函数的方法
	CallOnConnStart(connection IConnection)
	// SetOnConnClose 注册OnConnClose 钩子函数的方法
	SetOnConnClose(f func(connection IConnection))
	// CallOnConnClose 调用OnConnClose 钩子函数的方法
	CallOnConnClose(connection IConnection)
}

Jump to

Keyboard shortcuts

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