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 下午4:45 @Update Wangwengang 2021/8/17 下午4:45
@Title @Description @Author Wangwengang 2021/8/17 下午5:08 @Update Wangwengang 2021/8/17 下午5:08
Index ¶
- func NewDataPack() anet.Packet
- func NewServer(opts ...Option) anet.Server
- type ConnManager
- func (connMgr *ConnManager) Add(conn anet.Connection)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) ClearOneConn(connID uint32)
- func (connMgr *ConnManager) Get(connID uint32) (anet.Connection, error)
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Remove(conn anet.Connection)
- type DataPack
- type IRouter
- type Message
- 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) StartOneWorker(workerID int, taskQueue chan anet.Request)
- func (mh *MsgHandle) StartWorkerPool()
- type Option
- type Request
- type TcpConnection
- func (c *TcpConnection) Context() context.Context
- func (c *TcpConnection) GetConnID() uint32
- func (c *TcpConnection) GetProperty(key string) (interface{}, error)
- func (c *TcpConnection) GetTCPConnection() *net.TCPConn
- 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 TcpServer
- func (s *TcpServer) AddRouter(msgID uint32, router anet.Router)
- func (s *TcpServer) CallOnConnStart(conn anet.Connection)
- func (s *TcpServer) CallOnConnStop(conn anet.Connection)
- func (s *TcpServer) GetConnMgr() anet.ConnManager
- func (s *TcpServer) Packet() anet.Packet
- func (s *TcpServer) Serve()
- func (s *TcpServer) SetOnConnStart(hookFunc func(anet.Connection))
- func (s *TcpServer) SetOnConnStop(hookFunc func(anet.Connection))
- func (s *TcpServer) Start()
- func (s *TcpServer) Stop()
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 uint32)
ClearOneConn 利用ConnID获取一个链接 并且删除
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint32) (anet.Connection, error)
Get 利用ConnID获取链接
type IRouter ¶
type IRouter interface { PreHandle(request Request) //在处理conn业务之前的钩子方法 Handle(request Request) //处理conn业务的方法 PostHandle(request Request) //处理conn业务之后的钩子方法 }
路由接口, 这里面路由是 使用框架者给该链接自定的 处理业务方法 路由里的IRequest 则包含用该链接的链接信息和该链接的请求数据信息
type MsgHandle ¶
type MsgHandle struct { Apis map[uint32]anet.Router //存放每个MsgID 所对应的处理方法的map属性 WorkerPoolSize uint32 //业务工作Worker池的数量 TaskQueue []chan anet.Request //Worker负责取任务的消息队列 }
func (*MsgHandle) DoMsgHandler ¶
DoMsgHandler 马上以非阻塞方式处理消息
func (*MsgHandle) SendMsgToTaskQueue ¶
SendMsgToTaskQueue 将消息交给TaskQueue,由worker进行处理
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 TcpConnection ¶
type TcpConnection struct { //当前Conn属于哪个Server TCPServer anet.Server //当前连接的socket TCP套接字 Conn *net.TCPConn //当前连接的ID 也可以称作为SessionID,ID全局唯一 ConnID uint32 //消息管理MsgID和对应处理方法的消息管理模块 MsgHandler anet.MsgHandle sync.RWMutex // contains filtered or unexported fields }
func NewConnection ¶
func NewConnection(server anet.Server, conn *net.TCPConn, connID uint32, msgHandler anet.MsgHandle) *TcpConnection
NewConnection 创建连接的方法
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) 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 TcpServer ¶
type TcpServer struct { //服务器的名称 Name string //tcp4 or other IPVersion string //服务绑定的IP地址 IP string //服务绑定的端口 Port int //当前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 (*TcpServer) CallOnConnStart ¶
func (s *TcpServer) CallOnConnStart(conn anet.Connection)
CallOnConnStart 调用连接OnConnStart Hook函数
func (*TcpServer) CallOnConnStop ¶
func (s *TcpServer) CallOnConnStop(conn anet.Connection)
CallOnConnStop 调用连接OnConnStop Hook函数
func (*TcpServer) SetOnConnStart ¶
func (s *TcpServer) SetOnConnStart(hookFunc func(anet.Connection))
SetOnConnStart 设置该Server的连接创建时Hook函数
func (*TcpServer) SetOnConnStop ¶
func (s *TcpServer) SetOnConnStop(hookFunc func(anet.Connection))
SetOnConnStop 设置该Server的连接断开时的Hook函数