Documentation ¶
Index ¶
- func NewConnManager() iface.IConnManager
- func NewServer() iface.IServer
- type BaseRouter
- type ConnManager
- type Connection
- func (c *Connection) GetConnID() int32
- func (c *Connection) GetTCPConnection() *net.TCPConn
- func (c *Connection) Read()
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) SendMsg(msgID uint32, data []byte) error
- func (c *Connection) Start()
- func (c *Connection) Stop()
- func (c *Connection) Write()
- type DataPack
- type Message
- type MsgHandler
- type Request
- type Server
- func (s *Server) AddRouter(msgID uint32, router iface.Router)
- func (s *Server) CallOnConnClose(conn iface.IConnection)
- func (s *Server) CallOnConnStart(conn iface.IConnection)
- func (s *Server) GetConnManager() iface.IConnManager
- func (s *Server) Serve()
- func (s *Server) SetOnConnClose(f func(connection iface.IConnection))
- func (s *Server) SetOnConnStart(f func(connection iface.IConnection))
- func (s *Server) Start()
- func (s *Server) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnManager ¶
func NewConnManager() iface.IConnManager
Types ¶
type BaseRouter ¶
type BaseRouter struct { }
实现 Router 接口时,先嵌入这个 BaseRouter 基类,然后根据需求再对这个基类进行重写就好
func (*BaseRouter) PostHandle ¶
func (r *BaseRouter) PostHandle(req iface.IRequest)
PostHandle 处理业务之后的 hook
func (*BaseRouter) PreHandle ¶
func (r *BaseRouter) PreHandle(req iface.IRequest)
PreHandle 处理业务前的 hook
type ConnManager ¶
type ConnManager struct { // Conns 连接集合 connID => conn Conns map[uint32]iface.IConnection // contains filtered or unexported fields }
func (*ConnManager) AddConn ¶
func (cm *ConnManager) AddConn(conn iface.IConnection)
func (*ConnManager) GetConn ¶
func (cm *ConnManager) GetConn(connID uint32) (iface.IConnection, error)
func (*ConnManager) GetConnCnt ¶
func (cm *ConnManager) GetConnCnt() int
func (*ConnManager) RemoveAllConn ¶
func (cm *ConnManager) RemoveAllConn()
func (*ConnManager) RemoveConn ¶
func (cm *ConnManager) RemoveConn(conn iface.IConnection)
type Connection ¶
type Connection struct { // Server connection 所属服务器 Server iface.IServer // 当前连接的 socket TCP 套接字 Conn *net.TCPConn // 连接 ID ConnID int32 // 告知当前连接已经退出的 channel ExitChan chan bool // 改连接处理的的方法 MasHandler iface.IMsgHandler // contains filtered or unexported fields }
Connection 连接模块
func NewConnection ¶
func NewConnection(server iface.IServer, conn *net.TCPConn, connID int32, msgHandler iface.IMsgHandler) *Connection
NewConnection 初始化连接模块
func (*Connection) GetConnID ¶
func (c *Connection) GetConnID() int32
func (*Connection) GetTCPConnection ¶
func (c *Connection) GetTCPConnection() *net.TCPConn
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() net.Addr
func (*Connection) SendMsg ¶
func (c *Connection) SendMsg(msgID uint32, data []byte) error
SendMsg 将要发送给客户端的数据先进行封包,然后发送
func (*Connection) Start ¶
func (c *Connection) Start()
func (*Connection) Stop ¶
func (c *Connection) Stop()
type DataPack ¶
type DataPack struct { }
func NewDataPack ¶
func NewDataPack() *DataPack
func (*DataPack) GetHeadLen ¶
type MsgHandler ¶
type MsgHandler struct { // 工作队列 TaskQueue []chan iface.IRequest // worker 数量 WorkerPoolSize uint32 // contains filtered or unexported fields }
func NewMsgHandler ¶
func NewMsgHandler() *MsgHandler
func (*MsgHandler) Handle ¶
func (mh *MsgHandler) Handle(request iface.IRequest)
func (*MsgHandler) SendMsgToTaskQueue ¶
func (mh *MsgHandler) SendMsgToTaskQueue(req iface.IRequest)
SendMsgToTaskQueue 将消息发送给 队列,异步处理
func (*MsgHandler) StartOneWorker ¶
func (mh *MsgHandler) StartOneWorker(workID int, taskQueue chan iface.IRequest)
func (*MsgHandler) StartWorkPool ¶
func (mh *MsgHandler) StartWorkPool()
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) GetConn ¶
func (r *Request) GetConn() iface.IConnection
type Server ¶
type Server struct { ServerName string // 服务器名称 IPVersion string // IP 版本 IP string // IP Port int // 服务器监听端口 MsgHandler iface.IMsgHandler // 消息处理器 ConnManager iface.IConnManager // 连接管理器 OnConnStart func(connection iface.IConnection) // hook conn start OnConnClose func(connection iface.IConnection) // hook conn closed }
Server
@Description: 服务器结构
func (*Server) CallOnConnClose ¶
func (s *Server) CallOnConnClose(conn iface.IConnection)
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn iface.IConnection)
func (*Server) GetConnManager ¶
func (s *Server) GetConnManager() iface.IConnManager
func (*Server) SetOnConnClose ¶
func (s *Server) SetOnConnClose(f func(connection iface.IConnection))
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(f func(connection iface.IConnection))
Click to show internal directories.
Click to hide internal directories.