Documentation
¶
Index ¶
- Constants
- Variables
- type ConnCallback
- type ConnManager
- func (c *ConnManager) Add(conn IConnection)
- func (c *ConnManager) BroadcastMsg(msgId uint32, data []byte)
- func (c *ConnManager) ClearConn()
- func (c *ConnManager) ClearOneConn(connID uint32)
- func (c *ConnManager) Get(connID uint32) (IConnection, error)
- func (c *ConnManager) Len() int32
- func (c *ConnManager) Remove(conn IConnection)
- type Group
- type HandlerCallback
- type HandlerFunc
- type IConnection
- type ISocket
- type Msg
- type MsgHandler
- type ProtocolType
- type Request
- type RouteItem
- type Router
Constants ¶
View Source
const ( Tcp = iota WebSocket Http )
View Source
const HeartBeatTime = 300
HeartBeatTime 心跳时长 单位:秒
View Source
const MaxResTime = 10 // 最大响应时长,单位ms
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
ConnManager 链接管理器
func (*ConnManager) BroadcastMsg ¶
func (c *ConnManager) BroadcastMsg(msgId uint32, data []byte)
BroadcastMsg 广播数据
func (*ConnManager) ClearOneConn ¶
func (c *ConnManager) ClearOneConn(connID uint32)
ClearOneConn 删除指定ConnID的链接
func (*ConnManager) Get ¶
func (c *ConnManager) Get(connID uint32) (IConnection, error)
Get 根据ConnID获取链接
func (*ConnManager) Len ¶
func (c *ConnManager) Len() int32
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group 路由组
func (*Group) AddRoute ¶
func (g *Group) AddRoute(path string, callback HandlerCallback)
AddRoute 添加路由
type HandlerCallback ¶
type HandlerCallback interface{}
type HandlerFunc ¶
type IConnection ¶
type IConnection interface { Start() // 启动连接,让当前连接开始工作 Stop() // 停止连接,结束当前连接状态 GetTcpConnection() *net.TCPConn // 从当前连接获取原始的socket TCPConn GetWsConnection() *websocket.Conn // 从当前连接获取原始的websocket conn GetProtocolType() ProtocolType // 获取链接协议类型, TCP/WebSocket GetSocket() ISocket // 获取链接的Socket对象 GetConnID() uint32 // 获取当前连接ID IsClosed() bool // 当前链接是否已关闭 SetClosed() bool // 设置关闭状态,设置成功返回true,已关闭则返回false RemoteAddr() net.Addr // 获取远程客户端地址信息 SendMsg(msgId uint32, data []byte) error // 发送消息 }
IConnection 定义连接接口
type ISocket ¶
type ISocket interface { GetName() string // 获取Socket对象名称 GetId() string // 获取Socket对象ID GetHost() string // 获取监听(Server)/链接(Client)的主机地址 GetPort() int32 // 获取监听(Server)/链接(Client)的端口 Start() // 启动 Stop() // 停止运行 Run() // 运行 GetRouter() *Router // 获取消息路由器 GetConnMgr() *ConnManager // 获取链接管理器(Client的ConnMgr只会有一个Conn) SetOnConnStart(startCallBack ConnCallback) // 设置有新的链接Hook函数 SetOnConnStop(stopCallback ConnCallback) // 设置有链接断开Hook函数 CallOnConnStart(conn IConnection) // 调用链接OnConnStart Hook函数 CallOnConnStop(conn IConnection) // 调用链接OnConnStop Hook函数 }
ISocket Socket抽象接口,可以是Sever端/Client端
type MsgHandler ¶
type MsgHandler struct { WorkerPoolSize uint32 // 业务工作Worker池的数量 WorkerTaskSize uint32 // 每个Worker的可等待执行Task数量 TaskQueue []chan *Request // Worker负责取任务的消息队列 TaskExit []chan bool Router *Router // 路由 }
MsgHandler 消息处理器模块,msgHandler会有多个worker回来同时处理消息,conn发送的消息通过connId取模落入到某一个worker处理
func NewMsgHandler ¶
func NewMsgHandler(workerPoolSize uint32, workerTaskSize uint32) *MsgHandler
func (*MsgHandler) SendMsgToTaskQueue ¶
func (mh *MsgHandler) SendMsgToTaskQueue(request *Request)
SendMsgToTaskQueue 将消息交给TaskQueue,由worker进行处理
func (*MsgHandler) SetRouter ¶
func (mh *MsgHandler) SetRouter(router *Router)
SetRouter 为消息添加具体的处理逻辑(路由)
func (*MsgHandler) StartWorkerPool ¶
func (mh *MsgHandler) StartWorkerPool()
StartWorkerPool 启动worker工作池
type Request ¶
type Request struct { Conn IConnection // 已经和客户端建立好的 链接 Msg *Msg // 客户端请求的数据 }
Request 请求抽象
func NewRequest ¶
func NewRequest(conn IConnection, msg *Msg) *Request
Click to show internal directories.
Click to hide internal directories.