Documentation ¶
Index ¶
- Variables
- type BaseRouter
- func (b *BaseRouter) After()
- func (b *BaseRouter) EveryThingHandle(req liFace.IRequest, rsp liFace.IMessage)
- func (b *BaseRouter) NameSpace() string
- func (b *BaseRouter) PostHandle(req liFace.IRequest, rsp liFace.IMessage)
- func (b *BaseRouter) PreHandle(req liFace.IRequest, rsp liFace.IMessage) bool
- type Client
- func (c *Client) AddRouter(router liFace.IRouter)
- func (c *Client) CallOnConnStart(conn liFace.IConnection)
- func (c *Client) CallOnConnStop(conn liFace.IConnection)
- func (c *Client) GetClientType() proto.ServerType
- func (c *Client) GetConn() liFace.IConnection
- func (c *Client) GetConnMgr() liFace.IConnManager
- func (c *Client) GetHost() string
- func (c *Client) GetId() string
- func (c *Client) GetName() string
- func (c *Client) GetPort() int
- func (c *Client) Running()
- func (c *Client) SetClientType(sType proto.ServerType)
- func (c *Client) SetOnConnStart(hookFunc func(liFace.IConnection))
- func (c *Client) SetOnConnStop(hookFunc func(liFace.IConnection))
- func (c *Client) Start()
- func (c *Client) Stop()
- type ConnManager
- func (connMgr *ConnManager) Add(conn liFace.IConnection)
- func (connMgr *ConnManager) BroadcastMsg(msgName string, data []byte)
- func (connMgr *ConnManager) ClearConn()
- func (connMgr *ConnManager) Get(connID uint32) (liFace.IConnection, error)
- func (connMgr *ConnManager) Len() int
- func (connMgr *ConnManager) Remove(conn liFace.IConnection)
- type Connection
- func (c *Connection) CheckRpc(seq uint32, rsp liFace.IMessage) bool
- func (c *Connection) GetConnID() uint32
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetTCPConnection() *net.TCPConn
- func (c *Connection) GetTcpNetWork() liFace.INetWork
- func (c *Connection) IsClose() bool
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) RpcCall(msgName string, data []byte, success func(rsp liFace.IRespond), ...) error
- func (c *Connection) RpcPush(msgName string, data []byte) error
- func (c *Connection) RpcReply(msgName string, seq 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
- func (msg *Message) GetBody() []byte
- func (msg *Message) GetBodyLen() uint32
- func (msg *Message) GetMsgName() string
- func (msg *Message) GetMsgNameByte() []byte
- func (msg *Message) GetNameLen() uint32
- func (msg *Message) GetSeq() uint32
- func (msg *Message) GetType() byte
- func (msg *Message) SetBody(data []byte)
- func (msg *Message) SetBodyLen(len uint32)
- func (msg *Message) SetMsgName(name string)
- func (msg *Message) SetMsgNameByte(data []byte)
- func (msg *Message) SetNameLen(len uint32)
- func (msg *Message) SetSeq(seq uint32)
- func (msg *Message) SetType(t byte)
- type MsgHandle
- type Request
- type Respond
- type Server
- func (s *Server) AddRouter(router liFace.IRouter)
- func (s *Server) CallOnConnStart(conn liFace.IConnection)
- func (s *Server) CallOnConnStop(conn liFace.IConnection)
- func (s *Server) GetConnMgr() liFace.IConnManager
- func (s *Server) GetHost() string
- func (s *Server) GetId() string
- func (s *Server) GetName() string
- func (s *Server) GetPort() int
- func (s *Server) Running()
- func (s *Server) SetOnConnStart(hookFunc func(liFace.IConnection))
- func (s *Server) SetOnConnStop(hookFunc func(liFace.IConnection))
- func (s *Server) Start()
- func (s *Server) Stop()
- type WsConnection
- func (wsConn *WsConnection) Close()
- func (wsConn *WsConnection) GetId() uint64
- func (c *WsConnection) GetProperty(key string) (interface{}, error)
- func (wsConn *WsConnection) Push(proxyName string, funcName string, body []byte)
- func (c *WsConnection) RemoveProperty(key string)
- func (wsConn *WsConnection) Response(proxyName string, funcName string, seq uint32, body []byte)
- func (wsConn *WsConnection) Running()
- func (wsConn *WsConnection) SetOnClose(hookFunc func(*WsConnection))
- func (wsConn *WsConnection) SetOnMessage(hookFunc func(*WsConnection, *WsMessageReq, *WsMessageRsp))
- func (c *WsConnection) SetProperty(key string, value interface{})
- type WsMessageReq
- type WsMessageRsp
Constants ¶
This section is empty.
Variables ¶
View Source
var DataPackKey = []byte("msgprotokey12345")
View Source
var GateMessageKey = []byte("liFrameVeryGood!")
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
实现router时,先嵌入这个基类,然后根据需要对这个基类的方法进行重写
func (*BaseRouter) After ¶
func (b *BaseRouter) After()
这里之所以BaseRouter的方法都为空, 是因为有的Router不希望有PreHandle或PostHandle 所以Router全部继承BaseRouter的好处是,不需要实现PreHandle和PostHandle也可以实例化
func (*BaseRouter) EveryThingHandle ¶
func (b *BaseRouter) EveryThingHandle(req liFace.IRequest, rsp liFace.IMessage)
func (*BaseRouter) NameSpace ¶
func (b *BaseRouter) NameSpace() string
func (*BaseRouter) PostHandle ¶
func (b *BaseRouter) PostHandle(req liFace.IRequest, rsp liFace.IMessage)
type Client ¶
type Client struct { Server *Server // contains filtered or unexported fields }
func (*Client) CallOnConnStart ¶
func (c *Client) CallOnConnStart(conn liFace.IConnection)
func (*Client) CallOnConnStop ¶
func (c *Client) CallOnConnStop(conn liFace.IConnection)
func (*Client) GetClientType ¶
func (c *Client) GetClientType() proto.ServerType
func (*Client) GetConn ¶
func (c *Client) GetConn() liFace.IConnection
func (*Client) GetConnMgr ¶
func (c *Client) GetConnMgr() liFace.IConnManager
func (*Client) SetClientType ¶
func (c *Client) SetClientType(sType proto.ServerType)
func (*Client) SetOnConnStart ¶
func (c *Client) SetOnConnStart(hookFunc func(liFace.IConnection))
func (*Client) SetOnConnStop ¶
func (c *Client) SetOnConnStop(hookFunc func(liFace.IConnection))
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
连接管理模块
func (*ConnManager) BroadcastMsg ¶
func (connMgr *ConnManager) BroadcastMsg(msgName string, data []byte)
func (*ConnManager) Get ¶
func (connMgr *ConnManager) Get(connID uint32) (liFace.IConnection, error)
利用ConnID获取链接
type Connection ¶
type Connection struct { //当前Conn属于哪个Server TcpNetWork liFace.INetWork //当前连接的socket TCP套接字 Conn *net.TCPConn //当前连接的ID 也可以称作为SessionID,ID全局唯一 ConnID uint32 //消息管理msgName和对应处理方法的消息管理模块 MsgHandler liFace.IMsgHandle // contains filtered or unexported fields }
func NewConnection ¶
func NewConnection(netWork liFace.INetWork, conn *net.TCPConn, connID uint32, msgHandler liFace.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) GetTcpNetWork ¶
func (c *Connection) GetTcpNetWork() liFace.INetWork
func (*Connection) IsClose ¶
func (c *Connection) IsClose() bool
func (*Connection) RpcCall ¶
func (c *Connection) RpcCall(msgName string, data []byte, success func(rsp liFace.IRespond), fail func(rsp liFace.IRespond)) error
直接将Message数据发送数据给远程的TCP客户端
func (*Connection) RpcReply ¶
func (c *Connection) RpcReply(msgName string, seq uint32, data []byte) error
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type Message ¶
type Message struct { NameLen uint32 BodyLen uint32 //消息的长度 Name []byte //消息的ID Seq uint32 //序列号 Body []byte //消息的内容 Type byte }
func (*Message) GetMsgNameByte ¶
func (*Message) GetNameLen ¶
func (*Message) SetMsgNameByte ¶
func (*Message) SetNameLen ¶
type MsgHandle ¶
type MsgHandle struct { Apis map[string]*list.List //存放每个msgName 所对应的处理方法的map属性 WorkerPoolSize uint32 //业务工作Worker池的数量 TaskQueue []chan liFace.IRequest //Worker负责取任务的消息队列 TaskExit []chan bool }
func NewMsgHandle ¶
func (*MsgHandle) DoMsgHandler ¶
马上以非阻塞方式处理消息
func (*MsgHandle) SendMsgToTaskQueue ¶
将消息交给TaskQueue,由worker进行处理
func (*MsgHandle) StopWorkerPool ¶
func (mh *MsgHandle) StopWorkerPool()
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) GetMessage ¶
func (*Request) SetMessage ¶
type Respond ¶
type Respond struct {
// contains filtered or unexported fields
}
func (*Respond) GetMessage ¶
func (*Respond) GetRequest ¶
func (*Respond) SetMessage ¶
func (*Respond) SetRequest ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
iServer 接口实现,定义一个Server服务类
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn liFace.IConnection)
调用连接OnConnStart Hook函数
func (*Server) CallOnConnStop ¶
func (s *Server) CallOnConnStop(conn liFace.IConnection)
调用连接OnConnStop Hook函数
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(hookFunc func(liFace.IConnection))
设置该Server的连接创建时Hook函数
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(hookFunc func(liFace.IConnection))
设置该Server的连接断开时的Hook函数
type WsConnection ¶
type WsConnection struct {
// contains filtered or unexported fields
}
客户端连接
func NewWsConnection ¶
func NewWsConnection(wsSocket *websocket.Conn, cid uint64) *WsConnection
func (*WsConnection) Close ¶
func (wsConn *WsConnection) Close()
func (*WsConnection) GetId ¶
func (wsConn *WsConnection) GetId() uint64
func (*WsConnection) GetProperty ¶
func (c *WsConnection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*WsConnection) Push ¶
func (wsConn *WsConnection) Push(proxyName string, funcName string, body []byte)
func (*WsConnection) Response ¶
func (wsConn *WsConnection) Response(proxyName string, funcName string, seq uint32, body []byte)
func (*WsConnection) Running ¶
func (wsConn *WsConnection) Running()
func (*WsConnection) SetOnClose ¶
func (wsConn *WsConnection) SetOnClose(hookFunc func(*WsConnection))
func (*WsConnection) SetOnMessage ¶
func (wsConn *WsConnection) SetOnMessage(hookFunc func(*WsConnection, *WsMessageReq, *WsMessageRsp))
func (*WsConnection) SetProperty ¶
func (c *WsConnection) SetProperty(key string, value interface{})
设置链接属性
type WsMessageReq ¶
Click to show internal directories.
Click to hide internal directories.