Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnFunc ¶
type ConnFunc func(conn IConnection)
type IConnManager ¶
type IConnManager interface { //得到当前链接总数 Size() uint32 //添加链接 Add(connection IConnection) //删除链接 Remove(connId uint32) //根据 ConnId 获取链接 Get(connId uint32) (IConnection, error) //清除所有链接 Clear() }
*
- 链接管理模块抽象定义
type IConnection ¶
type IConnection interface { //启动链接 让当前的链接准备工作 Start() //停止链接 结束当前链接的工作 Stop() //获取当前链接绑定的 socket conn GetTCPConnection() *net.TCPConn //获取当前链接模块的链接 ID GetConnID() uint32 //获取远程客户端的 TCP状态 IP Port RemoteAddr() net.Addr //发送数据, 将数据发送给客户端 SendMsg(Id uint32, data []byte) error //设置连接属性 SetProperty(key string, value interface{}) //获取连接属性 GetProperty(key string) (value interface{}, err error) //移除连接属性 RemoveProperty(key string) }
type IMessageHandle ¶
type IMessageHandle interface { //调度、执行对应的 router 消息处理方法 DoMsgHandler(request IRequest) error //为消息添加具体的处理逻辑 AddRouter(msgId uint32, router IRouter) error //启动 worker 工作池 StartWorkerPool() //将消息发送给消息队列处理 SendMsgToTaskQueue(request IRequest) }
*
- 消息处理接口抽象
type IRequest ¶
type IRequest interface { //得到当前链接 GetConnection() IConnection //得到请求数据 GetData() []byte //获取 msg Id GetMsgId() uint32 }
type IRouter ¶
type IRouter interface { //路由之前的钩子方法 BeforeHandle(IRequest) //路由处理业务方法 Handle(IRequest) //路由之后的钩子方法 AfterHandle(IRequest) }
*
路由的抽象接口 路由里的数据都是 IRequest *
type IServer ¶
type IServer interface { //启动服务器 Start() error //运行服务器 Serve() //停止服务器 Stop() error //路由功能: 给当前的服务注册一个路由方法,供客户端链接处理方法 AddRouter(uint32, IRouter) error //获取当前服务的连接管理器 GetConnManager() IConnManager //注册 OnConnStart 钩子函数方法 SetOnConnStart(ConnFunc) //注册 OnConnStop 钩子函数方法 SetOnConnStop(ConnFunc) //调用 OnConnStart 钩子函数方法 CallOnConnStart(conn IConnection) //调用 OnConnStop 钩子函数方法 CallOnConnStop(conn IConnection) }
定义服务器抽象接口
Click to show internal directories.
Click to hide internal directories.