Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IConnManager ¶
type IConnManager interface {
Add(conn IConnection) //添加链接
Remove(conn IConnection) //删除连接
Get(connID int64) (IConnection, error) //利用ConnID获取链接
Len() int //获取当前连接
ClearConn() //删除并停止所有链接
ClearOneConn(connID int64) //删除并停止指定链接
}
IConnManager 连接管理抽象层
type IConnection ¶
type IConnection interface {
// Start 启动连接,让当前连接开始工作
Start()
// Stop 停止连接,结束当前连接状态M
Stop()
// GetTCPConnection 从当前连接获取原始的socket TCPConn
GetTCPConnection() *net.TCPConn
// GetConnID 获取当前连接ID
GetConnID() int64
// RemoteAddr 获取远程客户端地址信息
RemoteAddr() net.Addr
// SetSPublicKey 设置客户端的公钥
SetSPublicKey(key sm2.PublicKey)
// GetTcpServer 获取服务实例
GetTcpServer() IServer
// SendMsg 直接将Message数据发送数据给远程的TCP客户端(无缓冲)
SendMsg(msgId uint32, data []byte) error
// SendBuffMsg 直接将Message数据发送给远程的TCP客户端(有缓冲)
SendBuffMsg(msgId uint32, data []byte) error
// SetProperty 设置链接属性
SetProperty(key string, value interface{})
// GetProperty 获取链接属性
GetProperty(key string) (interface{}, error)
// RemoveProperty 移除链接属性
RemoveProperty(key string)
// KeepAlive 保持心跳激活
KeepAlive()
// IsAlive 判断心跳是否激活
IsAlive() bool
}
IConnection 定义连接接口
type IDataPack ¶
type IDataPack interface {
GetHeadLen() uint32 //获取包头长度方法
Pack(msg IMessage) ([]byte, error) //封包方法
Unpack([]byte) (IMessage, error) //拆包方法
}
IDataPack 封包数据和拆包数据 直接面向TCP连接中的数据流,为传输数据添加头部信息,用于处理TCP粘包问题。
type ILimiter ¶
type ILimiter interface {
// Increase 请求记数增加1
Increase()
IsAvailable() bool
}
ILimiter 定义连接接口
type IMessage ¶
type IMessage interface {
GetDataLen() uint32 //获取消息数据段长度
GetMsgId() uint32 //获取消息ID
GetData() []byte //获取消息内容
SetDataLen(uint32) //设置消息数据段长度
SetMsgId(uint32) //设计消息ID
SetData([]byte) //设计消息内容
}
IMessage 将请求的一个消息封装到message中,定义抽象层接口
type IMsgHandle ¶
type IMsgHandle interface {
DoMsgHandler(request IRequest) //马上以非阻塞方式处理消息
AddRouter(msgId uint32, router IRouter) //为消息添加具体的处理逻辑
StartWorkerPool() //启动worker工作池
SendMsgToTaskQueue(request IRequest) //将消息交给TaskQueue,由worker进行处理
}
IMsgHandle 消息管理抽象层
type IRequest ¶
type IRequest interface {
GetConnection() IConnection //获取请求连接信息
GetMsgID() uint32 //获取请求的消息ID
GetData() []byte //获取请求消息的数据
}
IRequest 接口: 实际上是把客户端请求的链接信息 和 请求的数据 包装到了 Request里
type IRouter ¶
type IRouter interface {
PreHandle(request IRequest) //在处理conn业务之前的钩子方法
Handle(request IRequest) //处理conn业务的方法
PostHandle(request IRequest) //处理conn业务之后的钩子方法
}
IRouter 路由接口, 这里面路由是 使用框架者给该链接自定的 处理业务方法 路由里的IRequest 则包含用该链接的链接信息和该链接的请求数据信息
type IServer ¶
type IServer interface {
// Start 启动服务器方法
Start()
// Stop 停止服务器方法
Stop()
// Serve 开启业务服务方法
Serve()
// AddRouter 路由功能:给当前服务注册一个路由业务方法,供客户端链接处理使用
AddRouter(msgId uint32, router IRouter)
// GetConnMgr 得到链接管理
GetConnMgr() IConnManager
// SetOnConnStart 设置该Server的连接创建时Hook函数
SetOnConnStart(func(IConnection))
// SetOnConnStop 设置该Server的连接断开时的Hook函数
SetOnConnStop(func(IConnection))
// CallOnConnStart 调用连接OnConnStart Hook函数
CallOnConnStart(conn IConnection)
// CallOnConnStop 调用连接OnConnStop Hook函数
CallOnConnStop(conn IConnection)
Packet() Packet
}
IServer 定义服务器接口
Click to show internal directories.
Click to hide internal directories.