Documentation ¶
Index ¶
- func NewServer() ziface.IServer
- type BaseRouter
- type ConnManager
- type Connection
- func (c *Connection) GetConnID() uint32
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetTCPConnection() *net.TCPConn
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendBuffMsg(msgId uint32, data []byte) error
- func (c *Connection) SendMsg(msgId uint32, data []byte) error
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) StartReader()
- func (c *Connection) StartWriter()
- func (c *Connection) Stop()
- type DataPack
- type Message
- type MsgHandle
- func (mh *MsgHandle) AddRouter(msgId uint32, router ziface.IRouter)
- func (mh *MsgHandle) DoMsgHandler(request ziface.IRequest)
- func (mh *MsgHandle) SendMsgToTaskQueue(request ziface.IRequest)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan ziface.IRequest)
- func (mh *MsgHandle) StartWorkerPool()
- type Request
- type Server
- func (s *Server) AddRouter(msgId uint32, router ziface.IRouter)
- func (s *Server) CallOnConnStart(conn ziface.IConnection)
- func (s *Server) CallOnConnStop(conn ziface.IConnection)
- func (s *Server) GetConnMgr() ziface.IConnManager
- func (s *Server) Serve()
- func (s *Server) SetOnConnStart(hookFunc func(ziface.IConnection))
- func (s *Server) SetOnConnStop(hookFunc func(ziface.IConnection))
- func (s *Server) Start()
- func (s *Server) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
实现router时,先嵌入这个基类,然后根据需要对这个基类的方法进行重写
func (*BaseRouter) Handle ¶
func (br *BaseRouter) Handle(req ziface.IRequest)
func (*BaseRouter) PostHandle ¶
func (br *BaseRouter) PostHandle(req ziface.IRequest)
func (*BaseRouter) PreHandle ¶
func (br *BaseRouter) PreHandle(req ziface.IRequest)
这里之所以BaseRouter的方法都为空, 是因为有的Router不希望有PreHandle或PostHandle 所以Router全部继承BaseRouter的好处是,不需要实现PreHandle和PostHandle也可以实例化
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
连接管理模块
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint32) (ziface.IConnection, error)
利用ConnID获取链接
type Connection ¶
type Connection struct { //当前Conn属于哪个Server TcpServer ziface.IServer //当前连接的socket TCP套接字 Conn *net.TCPConn //当前连接的ID 也可以称作为SessionID,ID全局唯一 ConnID uint32 //消息管理MsgId和对应处理方法的消息管理模块 MsgHandler ziface.IMsgHandle //告知该链接已经退出/停止的channel ExitBuffChan chan bool // contains filtered or unexported fields }
func NewConntion ¶
func NewConntion(server ziface.IServer, conn *net.TCPConn, connID uint32, msgHandler ziface.IMsgHandle) *Connection
创建连接的方法
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*Connection) GetTCPConnection ¶
func (c *Connection) GetTCPConnection() *net.TCPConn
从当前连接获取原始的socket TCPConn
func (*Connection) SendBuffMsg ¶
func (c *Connection) SendBuffMsg(msgId uint32, data []byte) error
func (*Connection) SendMsg ¶
func (c *Connection) SendMsg(msgId uint32, data []byte) error
直接将Message数据发送数据给远程的TCP客户端
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type MsgHandle ¶
type MsgHandle struct { Apis map[uint32]ziface.IRouter //存放每个MsgId 所对应的处理方法的map属性 WorkerPoolSize uint32 //业务工作Worker池的数量 TaskQueue []chan ziface.IRequest //Worker负责取任务的消息队列 }
func NewMsgHandle ¶
func NewMsgHandle() *MsgHandle
func (*MsgHandle) DoMsgHandler ¶
马上以非阻塞方式处理消息
func (*MsgHandle) SendMsgToTaskQueue ¶
将消息交给TaskQueue,由worker进行处理
func (*MsgHandle) StartOneWorker ¶
启动一个Worker工作流程
type Server ¶
type Server struct { //服务器的名称 Name string //tcp4 or other IPVersion string //服务绑定的IP地址 IP string //服务绑定的端口 Port int //当前Server的链接管理器 ConnMgr ziface.IConnManager //该Server的连接创建时Hook函数 OnConnStart func(conn ziface.IConnection) //该Server的连接断开时的Hook函数 OnConnStop func(conn ziface.IConnection) // contains filtered or unexported fields }
iServer 接口实现,定义一个Server服务类
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn ziface.IConnection)
调用连接OnConnStart Hook函数
func (*Server) CallOnConnStop ¶
func (s *Server) CallOnConnStop(conn ziface.IConnection)
调用连接OnConnStop Hook函数
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(ziface.IConnection))
设置该Server的连接创建时Hook函数
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(ziface.IConnection))
设置该Server的连接断开时的Hook函数
Click to show internal directories.
Click to hide internal directories.