Documentation
¶
Overview ¶
@Title @Description @Author Wangwengang 2021/8/17 下午5:21 @Update Wangwengang 2021/8/17 下午5:21
@Title @Description @Author Wangwengang 2021/8/17 下午5:25 @Update Wangwengang 2021/8/17 下午5:25
@Title @Description @Author Wangwengang 2021/8/17 下午5:26 @Update Wangwengang 2021/8/17 下午5:26
@Title @Description @Author Wangwengang 2021/8/17 下午5:18 @Update Wangwengang 2021/8/17 下午5:18
@Title @Description @Author Wangwengang 2021/8/17 下午5:11 @Update Wangwengang 2021/8/17 下午5:11
@Title @Description @Author Wangwengang 2021/8/17 下午9:54 @Update Wangwengang 2021/8/17 下午9:54
@Title @Description @Author Wangwengang 2021/8/17 下午9:55 @Update Wangwengang 2021/8/17 下午9:55
@Title @Description @Author Wangwengang 2021/8/17 下午5:08 @Update Wangwengang 2021/8/17 下午5:08
@Title @Description @Author Wangwengang 2021/8/17 下午4:45 @Update Wangwengang 2021/8/17 下午4:45
@Title @Description @Author Wangwengang 2021/8/19 下午11:27 @Update Wangwengang 2021/8/19 下午11:27
Index ¶
- func NewConnection(server anet.Server, conn *net.TCPConn, connID uint64, ...) anet.Connection
- func NewDataPack() anet.Packet
- func NewServer(opts ...Option) anet.Server
- func NewWsConnection(server anet.Server, conn *websocket.Conn, connID uint64, ...) anet.Connection
- type BaseRouter
- type ConnManager
- func (connMgr *ConnManager) Add(conn anet.Connection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) ClearOneConn(connID uint64)
- func (connMgr *ConnManager) Get(connID uint64) (anet.Connection, error)
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Remove(conn anet.Connection)
- type DataPack
- type Message
- func (msg *Message) GetData() []byte
- func (msg *Message) GetDataLen() uint32
- func (msg *Message) GetMsgID() uint32
- func (msg *Message) GetSeq() uint32
- func (msg *Message) GetVer() uint32
- func (msg *Message) SetData(data []byte)
- func (msg *Message) SetDataLen(len uint32)
- func (msg *Message) SetMsgID(msgID uint32)
- type MsgHandle
- func (mh *MsgHandle) AddRouter(msgID uint32, router anet.Router)
- func (mh *MsgHandle) DoMsgHandler(request anet.Request)
- func (mh *MsgHandle) SendMsgToTaskQueue(request anet.Request)
- func (mh *MsgHandle) SetRpcxRouter(router anet.RpcxRouter)
- func (mh *MsgHandle) StartOneWorker(workerID int, taskQueue chan anet.Request)
- func (mh *MsgHandle) StartWorkerPool()
- type Option
- type Request
- type RpcxRouter
- type Server
- func (s *Server) AddRouter(msgID uint32, router anet.Router)
- func (s *Server) CallOnConnStart(conn anet.Connection)
- func (s *Server) CallOnConnStop(conn anet.Connection)
- func (s *Server) GenID() uint64
- func (s *Server) GetConnMgr() anet.ConnManager
- func (s *Server) Packet() anet.Packet
- func (s *Server) Serve()
- func (s *Server) SetOnConnStart(hookFunc func(anet.Connection))
- func (s *Server) SetOnConnStop(hookFunc func(anet.Connection))
- func (s *Server) SetRpcxRouter(router anet.RpcxRouter)
- func (s *Server) StartTcp()
- func (s *Server) StartWebsocket()
- func (s *Server) Stop()
- type TcpConnection
- func (c *TcpConnection) Context() context.Context
- func (c *TcpConnection) GetConnID() uint64
- func (c *TcpConnection) GetProperty(key string) (interface{}, error)
- func (c *TcpConnection) GetTcpConnection() *net.TCPConn
- func (c *TcpConnection) GetWsConnection() *websocket.Conn
- func (c *TcpConnection) RemoteAddr() net.Addr
- func (c *TcpConnection) RemoveProperty(key string)
- func (c *TcpConnection) SendBuffMsg(msgID uint32, data []byte) error
- func (c *TcpConnection) SendMsg(msgID uint32, data []byte) error
- func (c *TcpConnection) SetProperty(key string, value interface{})
- func (c *TcpConnection) Start()
- func (c *TcpConnection) StartReader()
- func (c *TcpConnection) StartWriter()
- func (c *TcpConnection) Stop()
- type WsConnection
- func (c *WsConnection) Context() context.Context
- func (c *WsConnection) GetConnID() uint64
- func (c *WsConnection) GetProperty(key string) (interface{}, error)
- func (c *WsConnection) GetTcpConnection() *net.TCPConn
- func (c *WsConnection) GetWsConnection() *websocket.Conn
- func (c *WsConnection) RemoteAddr() net.Addr
- func (c *WsConnection) RemoveProperty(key string)
- func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte) error
- func (c *WsConnection) SendMsg(msgID uint32, data []byte) error
- func (c *WsConnection) SetProperty(key string, value interface{})
- func (c *WsConnection) Start()
- func (c *WsConnection) StartReader()
- func (c *WsConnection) StartWriter()
- func (c *WsConnection) Stop()
- type WsHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func (*ConnManager) ClearOneConn ¶
func (connMgr *ConnManager) ClearOneConn(connID uint64)
ClearOneConn 利用ConnID获取一个链接 并且删除
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint64) (anet.Connection, error)
Get 利用ConnID获取链接
type MsgHandle ¶
type MsgHandle struct { Apis map[uint32]anet.Router //存放每个MsgID 所对应的处理方法的map属性 Rpcx anet.RpcxRouter WorkerPoolSize uint32 //业务工作Worker池的数量 TaskQueue []chan anet.Request //Worker负责取任务的消息队列 }
func (*MsgHandle) DoMsgHandler ¶
DoMsgHandler 马上以非阻塞方式处理消息
func (*MsgHandle) SendMsgToTaskQueue ¶
SendMsgToTaskQueue 将消息交给TaskQueue,由worker进行处理
func (*MsgHandle) SetRpcxRouter ¶
func (mh *MsgHandle) SetRpcxRouter(router anet.RpcxRouter)
SetRpcxRouter 为消息添加Rpcx处理逻辑
func (*MsgHandle) StartOneWorker ¶
StartOneWorker 启动一个Worker工作流程
func (*MsgHandle) StartWorkerPool ¶
func (mh *MsgHandle) StartWorkerPool()
StartWorkerPool 启动worker工作池
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request 请求
func (*Request) GetConnection ¶
func (r *Request) GetConnection() anet.Connection
GetConnection 获取请求连接信息
type Server ¶
type Server struct { //服务器的名称 Name string //tcp4 or other IPVersion string //服务绑定的IP地址 IP string //服务绑定的端口 Port int // Websocket Addr WsAddr string //当前Server的链接管理器 ConnMgr anet.ConnManager //该Server的连接创建时Hook函数 OnConnStart func(conn anet.Connection) //该Server的连接断开时的Hook函数 OnConnStop func(conn anet.Connection) // contains filtered or unexported fields }
Server 接口实现,定义一个Server服务类
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn anet.Connection)
CallOnConnStart 调用连接OnConnStart Hook函数
func (*Server) CallOnConnStop ¶
func (s *Server) CallOnConnStop(conn anet.Connection)
CallOnConnStop 调用连接OnConnStop Hook函数
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(anet.Connection))
SetOnConnStart 设置该Server的连接创建时Hook函数
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(anet.Connection))
SetOnConnStop 设置该Server的连接断开时的Hook函数
func (*Server) SetRpcxRouter ¶
func (s *Server) SetRpcxRouter(router anet.RpcxRouter)
AddRouter 路由功能:给当前服务注册一个路由业务方法,供客户端链接处理使用
type TcpConnection ¶
type TcpConnection struct { //当前Conn属于哪个Server TCPServer anet.Server //当前连接的socket TCP套接字 Conn *net.TCPConn //当前连接的ID 也可以称作为SessionID,ID全局唯一 ConnID uint64 //消息管理MsgID和对应处理方法的消息管理模块 MsgHandler anet.MsgHandle sync.RWMutex // contains filtered or unexported fields }
func (*TcpConnection) Context ¶
func (c *TcpConnection) Context() context.Context
返回ctx,用于用户自定义的go程获取连接退出状态
func (*TcpConnection) GetProperty ¶
func (c *TcpConnection) GetProperty(key string) (interface{}, error)
GetProperty 获取链接属性
func (*TcpConnection) GetTcpConnection ¶
func (c *TcpConnection) GetTcpConnection() *net.TCPConn
GetTCPConnection 从当前连接获取原始的socket TCPConn
func (*TcpConnection) GetWsConnection ¶
func (c *TcpConnection) GetWsConnection() *websocket.Conn
GetTCPConnection 从当前连接获取原始的socket TCPConn
func (*TcpConnection) RemoteAddr ¶
func (c *TcpConnection) RemoteAddr() net.Addr
RemoteAddr 获取远程客户端地址信息
func (*TcpConnection) RemoveProperty ¶
func (c *TcpConnection) RemoveProperty(key string)
RemoveProperty 移除链接属性
func (*TcpConnection) SendBuffMsg ¶
func (c *TcpConnection) SendBuffMsg(msgID uint32, data []byte) error
SendBuffMsg 发生BuffMsg
func (*TcpConnection) SendMsg ¶
func (c *TcpConnection) SendMsg(msgID uint32, data []byte) error
SendMsg 直接将Message数据发送数据给远程的TCP客户端
func (*TcpConnection) SetProperty ¶
func (c *TcpConnection) SetProperty(key string, value interface{})
SetProperty 设置链接属性
func (*TcpConnection) StartReader ¶
func (c *TcpConnection) StartReader()
StartReader 读消息Goroutine,用于从客户端中读取数据
func (*TcpConnection) StartWriter ¶
func (c *TcpConnection) StartWriter()
StartWriter 写消息Goroutine, 用户将数据发送给客户端
type WsConnection ¶
type WsConnection struct { //当前Conn属于哪个Server TCPServer anet.Server //当前连接的socket TCP套接字 Conn *websocket.Conn //当前连接的ID 也可以称作为SessionID,ID全局唯一 ConnID uint64 //消息管理MsgID和对应处理方法的消息管理模块 MsgHandler anet.MsgHandle sync.RWMutex // contains filtered or unexported fields }
func (*WsConnection) Context ¶
func (c *WsConnection) Context() context.Context
返回ctx,用于用户自定义的go程获取连接退出状态
func (*WsConnection) GetProperty ¶
func (c *WsConnection) GetProperty(key string) (interface{}, error)
GetProperty 获取链接属性
func (*WsConnection) GetTcpConnection ¶
func (c *WsConnection) GetTcpConnection() *net.TCPConn
GetTCPConnection 从当前连接获取原始的socket TCPConn
func (*WsConnection) GetWsConnection ¶
func (c *WsConnection) GetWsConnection() *websocket.Conn
GetTCPConnection 从当前连接获取原始的socket TCPConn
func (*WsConnection) RemoteAddr ¶
func (c *WsConnection) RemoteAddr() net.Addr
RemoteAddr 获取远程客户端地址信息
func (*WsConnection) RemoveProperty ¶
func (c *WsConnection) RemoveProperty(key string)
RemoveProperty 移除链接属性
func (*WsConnection) SendBuffMsg ¶
func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte) error
SendBuffMsg 发生BuffMsg
func (*WsConnection) SendMsg ¶
func (c *WsConnection) SendMsg(msgID uint32, data []byte) error
SendMsg 直接将Message数据发送数据给远程的TCP客户端
func (*WsConnection) SetProperty ¶
func (c *WsConnection) SetProperty(key string, value interface{})
SetProperty 设置链接属性
func (*WsConnection) StartReader ¶
func (c *WsConnection) StartReader()
StartReader 读消息Goroutine,用于从客户端中读取数据
func (*WsConnection) StartWriter ¶
func (c *WsConnection) StartWriter()
StartWriter 写消息Goroutine, 用户将数据发送给客户端