Documentation ¶
Index ¶
- Constants
- type BaseRouter
- type CSocket
- type ConnData
- type ConnDataMap
- type ConnState
- type DataPack
- type ICSocket
- type IDataPack
- type IMessage
- type IMsgHandler
- type INetClient
- type INetClients
- type INetServer
- type INetService
- type INodeClient
- type INodeServer
- type INodeService
- type IRequest
- type IRoleMsgHandler
- type IRouter
- type ISSocket
- type ISceneMsgHandler
- type IServerMsgHandler
- type ISession
- type ISessionManager
- type ISocket
- type Message
- func (m *Message) GetData() []byte
- func (m *Message) GetDataLen() uint32
- func (m *Message) GetMsgID() uint32
- func (m *Message) GetMsgType() uint8
- func (m *Message) SetData(data []byte)
- func (m *Message) SetDataLen(dataLen uint32)
- func (m *Message) SetMsgID(msgID uint32)
- func (m *Message) SetMsgType(msgType uint8)
- type MsgErrCode
- type MsgHandler
- func (mh *MsgHandler) AddRouter(msgID uint32, router IRouter)
- func (mh *MsgHandler) DispatchByMsgID(request IRequest)
- func (mh *MsgHandler) DispatchByRoleID(request IRequest)
- func (mh *MsgHandler) DispatchBySceneID(request IRequest)
- func (mh *MsgHandler) DispatchByServerID(request IRequest)
- func (mh *MsgHandler) DoMsg(request IRequest)
- func (mh *MsgHandler) IsUseWorkPool() bool
- func (mh *MsgHandler) StartWorkPool()
- type MsgType
- type NetClient
- type NetClients
- type NetEventType
- type NetServer
- func (s *NetServer) GetNodeService() INodeService
- func (s *NetServer) GetSession(sessionID int64) (ISession, error)
- func (s *NetServer) GetSessionManager() ISessionManager
- func (s *NetServer) GetSocket() ISocket
- func (s *NetServer) Listen() error
- func (s *NetServer) SetNodeService(service INodeService)
- type NetService
- type NetState
- type NodeClient
- func (nc *NodeClient) AddConnServer()
- func (nc *NodeClient) OnMasterRouter()
- func (nc *NodeClient) Serve()
- func (nc *NodeClient) SetReportInfo(serverType ServerType)
- func (nc *NodeClient) Start()
- func (nc *NodeClient) Stop()
- func (nc *NodeClient) UpdateOnline(count int)
- func (nc *NodeClient) UpdateServerState(state ServerState)
- type NodeServer
- type NodeService
- func (ns *NodeService) GetDataPack() IDataPack
- func (ns *NodeService) GetMsgHandler() IMsgHandler
- func (ns *NodeService) GetNodeConfig() *configure.NetNode
- func (ns *NodeService) GetNodeID() int32
- func (ns *NodeService) GetOnConnected() FuncArgs
- func (ns *NodeService) GetOnDisconnected() FuncArgs
- func (ns *NodeService) IsStop() bool
- func (ns *NodeService) RegisterRouter(msgID uint32, router IRouter)
- func (ns *NodeService) SetOnConnected(onConnected FuncArgs)
- func (ns *NodeService) SetOnDisconnected(onDisconnected FuncArgs)
- func (ns *NodeService) SetOnStart(onStart FuncArgs)
- func (ns *NodeService) SetOnStop(onStop FuncArgs)
- type Request
- type SSocket
- type ServState
- type Session
- func (s *Session) Context() context.Context
- func (s *Session) GetConn() net.Conn
- func (s *Session) GetID() int64
- func (s *Session) GetNetService() INetService
- func (s *Session) GetNodeService() INodeService
- func (s *Session) GetProperty(key string) interface{}
- func (s *Session) LocalAddr() string
- func (s *Session) RemoteAddr() string
- func (s *Session) RemoveProperty(key string)
- func (s *Session) SendJson(msgID uint32, msg interface{}) error
- func (s *Session) SendJsonBuffer(msgID uint32, data []byte) error
- func (s *Session) SendProto(msgID uint32, msg *proto.Message) error
- func (s *Session) SendProtoBuffer(msgID uint32, data []byte) error
- func (s *Session) SetNetService(service INetService)
- func (s *Session) SetProperty(key string, value interface{})
- func (s *Session) Start()
- func (s *Session) Stop()
- type SessionManager
- func (cm *SessionManager) Add(session ISession)
- func (cm *SessionManager) Clear()
- func (cm *SessionManager) ClearSession(sID int64)
- func (cm *SessionManager) GetSession(sessionID int64) (ISession, error)
- func (cm *SessionManager) Len() int
- func (cm *SessionManager) Remove(session ISession)
- func (cm *SessionManager) RemoveById(sessionID int64)
- type Socket
Constants ¶
View Source
const DEFAULT_HEADER_LEN uint32 = 9
View Source
const MAX_MSG_WORKER_SIZE = 100
View Source
const MAX_PACKAGE_SIZE = 32 * 1024
View Source
const MSG_CHAN_BUFF_LEN = 10 * 1024
View Source
const MSG_WORKER_POOL_SIZE = 1000
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct{}
func (*BaseRouter) PostHandle ¶
func (br *BaseRouter) PostHandle(request IRequest) MsgErrCode
消息处理后调用
type CSocket ¶
type CSocket struct {
Socket
}
func NewCSocket ¶
func NewCSocket(netService INetService) *CSocket
type ConnDataMap ¶
func (ConnDataMap) Add ¶
func (m ConnDataMap) Add(connData *ConnData)
func (ConnDataMap) GetByServerID ¶
func (m ConnDataMap) GetByServerID(serverID int32) *ConnData
func (ConnDataMap) GetByServerType ¶
func (m ConnDataMap) GetByServerType(serverType int32) *ConnData
func (ConnDataMap) Remove ¶
func (m ConnDataMap) Remove(serverID int32)
type DataPack ¶
type DataPack struct{}
func NewDataPack ¶
func NewDataPack() *DataPack
func (*DataPack) GetHeadLen ¶
type IMsgHandler ¶
type INetClient ¶
抽象网络管理器-客户端
type INetClients ¶
type INetServer ¶
type INetServer interface { GetSessionManager() ISessionManager GetSession(sessionID int64) (ISession, error) Listen() error }
抽象网络管理器-服务器端
type INetService ¶
type INetService interface { GetSocket() ISocket SetNodeService(service INodeService) GetNodeService() INodeService }
netservice 接口
type INodeClient ¶
type INodeClient interface { // 作为客户端上报服务器信息 SetReportInfo(serverType ServerType) UpdateOnline(count int) UpdateServerState(state ServerState) OnMasterRouter() AddConnServer() }
type INodeServer ¶
type INodeServer interface { }
type INodeService ¶
type INodeService interface { GetMsgHandler() IMsgHandler GetDataPack() IDataPack GetNodeConfig() *configure.NetNode RegisterRouter(msgID uint32, router IRouter) SetOnStart(onStart FuncArgs) SetOnStop(onStop FuncArgs) SetOnConnected(onConnected FuncArgs) SetOnDisconnected(onDisconnected FuncArgs) GetOnConnected() FuncArgs GetOnDisconnected() FuncArgs IsStop() bool GetNodeID() int32 }
node 服务接口
type IRequest ¶
type IRequest interface { GetSession() ISession GetData() []byte GetMsgID() uint32 GetMsgType() uint8 }
包装消息和连接
type IRoleMsgHandler ¶
type IRoleMsgHandler interface {
DispatchByRoleID(request IRequest)
}
type IRouter ¶
type IRouter interface { PreHandle(request IRequest) MsgErrCode Handle(request IRequest) MsgErrCode PostHandle(request IRequest) MsgErrCode }
type ISceneMsgHandler ¶
type ISceneMsgHandler interface {
DispatchBySceneID(request IRequest)
}
type IServerMsgHandler ¶
type IServerMsgHandler interface {
DispatchByServerID(request IRequest)
}
type ISession ¶
type ISession interface { Start() Stop() GetID() int64 Context() context.Context GetConn() net.Conn // 获取原始连接 RemoteAddr() string // 获取远程客户端地址 LocalAddr() string // SendProto(msgID uint32, msg *proto.Message) error SendJson(msgID uint32, msg interface{}) error SendProtoBuffer(msgID uint32, data []byte) error SendJsonBuffer(msgID uint32, data []byte) error SetProperty(key string, value interface{}) GetProperty(key string) interface{} RemoveProperty(key string) SetNetService(service INetService) GetNetService() INetService GetNodeService() INodeService }
type ISessionManager ¶
type Message ¶
func (*Message) GetDataLen ¶
func (*Message) GetMsgType ¶
func (*Message) SetDataLen ¶
func (*Message) SetMsgType ¶
type MsgErrCode ¶
type MsgErrCode int64
const ( MEC_OK MsgErrCode = 0 MEC_ERR MsgErrCode = 1 MEC_MSGID MsgErrCode = 2 MEC_MSG_UNMARSHAL MsgErrCode = 3 MEC_MSG_MARSHAL MsgErrCode = 3 )
type MsgHandler ¶
type MsgHandler struct { // 根据消息id指定路由 Apis map[uint32]IRouter // contains filtered or unexported fields }
func NewMsgHandler ¶
func NewMsgHandler() *MsgHandler
func (*MsgHandler) AddRouter ¶
func (mh *MsgHandler) AddRouter(msgID uint32, router IRouter)
func (*MsgHandler) DispatchByMsgID ¶
func (mh *MsgHandler) DispatchByMsgID(request IRequest)
func (*MsgHandler) DispatchByRoleID ¶
func (mh *MsgHandler) DispatchByRoleID(request IRequest)
func (*MsgHandler) DispatchBySceneID ¶
func (mh *MsgHandler) DispatchBySceneID(request IRequest)
func (*MsgHandler) DispatchByServerID ¶
func (mh *MsgHandler) DispatchByServerID(request IRequest)
func (*MsgHandler) DoMsg ¶
func (mh *MsgHandler) DoMsg(request IRequest)
func (*MsgHandler) IsUseWorkPool ¶
func (mh *MsgHandler) IsUseWorkPool() bool
func (*MsgHandler) StartWorkPool ¶
func (mh *MsgHandler) StartWorkPool()
type NetClient ¶
type NetClient struct { NetService // contains filtered or unexported fields }
func NewNetClient ¶
func NewNetClient(service INodeService) *NetClient
func (*NetClient) GetNodeService ¶
func (c *NetClient) GetNodeService() INodeService
func (*NetClient) GetSession ¶
func (*NetClient) SetNodeService ¶
func (c *NetClient) SetNodeService(service INodeService)
type NetClients ¶
type NetClients struct {
// contains filtered or unexported fields
}
func NewNetClients ¶
func NewNetClients(service INodeService) *NetClients
func (*NetClients) AddConnServer ¶
func (cs *NetClients) AddConnServer(connData *ConnData)
func (*NetClients) ProcessExecute ¶
func (cs *NetClients) ProcessExecute()
func (*NetClients) ResetConnState ¶
func (cs *NetClients) ResetConnState(nodeID int32, state ConnState)
type NetEventType ¶
type NetEventType uint32
const ( NET_EOF NetEventType = 0 NET_ERROR NetEventType = 1 NET_TIMEOUT NetEventType = 2 NET_CONNECTED NetEventType = 3 )
type NetServer ¶
type NetServer struct { NetService // contains filtered or unexported fields }
func NewNetServer ¶
func NewNetServer(nodeService INodeService, servIP string, servPort int) *NetServer
func (*NetServer) GetNodeService ¶
func (s *NetServer) GetNodeService() INodeService
func (*NetServer) GetSessionManager ¶
func (s *NetServer) GetSessionManager() ISessionManager
func (*NetServer) SetNodeService ¶
func (s *NetServer) SetNodeService(service INodeService)
type NetService ¶
type NetService struct {
// contains filtered or unexported fields
}
type NodeClient ¶
type NodeClient struct { NodeService // contains filtered or unexported fields }
func NewNodeClient ¶
func NewNodeClient(config *configure.NetNode) *NodeClient
func (*NodeClient) AddConnServer ¶
func (nc *NodeClient) AddConnServer()
func (*NodeClient) OnMasterRouter ¶
func (nc *NodeClient) OnMasterRouter()
func (*NodeClient) Serve ¶
func (nc *NodeClient) Serve()
func (*NodeClient) SetReportInfo ¶
func (nc *NodeClient) SetReportInfo(serverType ServerType)
func (*NodeClient) Start ¶
func (nc *NodeClient) Start()
func (*NodeClient) Stop ¶
func (nc *NodeClient) Stop()
func (*NodeClient) UpdateOnline ¶
func (nc *NodeClient) UpdateOnline(count int)
func (*NodeClient) UpdateServerState ¶
func (nc *NodeClient) UpdateServerState(state ServerState)
type NodeServer ¶
type NodeServer struct { NodeService // contains filtered or unexported fields }
func NewNodeServer ¶
func NewNodeServer(config *configure.NetNode) *NodeServer
func (*NodeServer) Serve ¶
func (s *NodeServer) Serve()
func (*NodeServer) Start ¶
func (s *NodeServer) Start()
func (*NodeServer) Stop ¶
func (s *NodeServer) Stop()
type NodeService ¶
type NodeService struct {
// contains filtered or unexported fields
}
func (*NodeService) GetDataPack ¶
func (ns *NodeService) GetDataPack() IDataPack
func (*NodeService) GetMsgHandler ¶
func (ns *NodeService) GetMsgHandler() IMsgHandler
func (*NodeService) GetNodeConfig ¶
func (ns *NodeService) GetNodeConfig() *configure.NetNode
func (*NodeService) GetNodeID ¶
func (ns *NodeService) GetNodeID() int32
func (*NodeService) GetOnConnected ¶
func (ns *NodeService) GetOnConnected() FuncArgs
func (*NodeService) GetOnDisconnected ¶
func (ns *NodeService) GetOnDisconnected() FuncArgs
func (*NodeService) IsStop ¶
func (ns *NodeService) IsStop() bool
func (*NodeService) RegisterRouter ¶
func (ns *NodeService) RegisterRouter(msgID uint32, router IRouter)
func (*NodeService) SetOnConnected ¶
func (ns *NodeService) SetOnConnected(onConnected FuncArgs)
func (*NodeService) SetOnDisconnected ¶
func (ns *NodeService) SetOnDisconnected(onDisconnected FuncArgs)
func (*NodeService) SetOnStart ¶
func (ns *NodeService) SetOnStart(onStart FuncArgs)
func (*NodeService) SetOnStop ¶
func (ns *NodeService) SetOnStop(onStop FuncArgs)
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func (*Request) GetMsgType ¶
func (*Request) GetSession ¶
type SSocket ¶
type SSocket struct { Socket // contains filtered or unexported fields }
func NewSSocket ¶
func NewSSocket(netService INetService, ip string, port int) *SSocket
type Session ¶
func NewSession ¶
func (*Session) GetNetService ¶
func (s *Session) GetNetService() INetService
func (*Session) GetNodeService ¶
func (s *Session) GetNodeService() INodeService
func (*Session) GetProperty ¶
func (*Session) RemoteAddr ¶
func (*Session) RemoveProperty ¶
func (*Session) SendProtoBuffer ¶
func (*Session) SetNetService ¶
func (s *Session) SetNetService(service INetService)
func (*Session) SetProperty ¶
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
func NewSessionManager ¶
func NewSessionManager() *SessionManager
func (*SessionManager) Add ¶
func (cm *SessionManager) Add(session ISession)
func (*SessionManager) Clear ¶
func (cm *SessionManager) Clear()
func (*SessionManager) ClearSession ¶
func (cm *SessionManager) ClearSession(sID int64)
func (*SessionManager) GetSession ¶
func (cm *SessionManager) GetSession(sessionID int64) (ISession, error)
func (*SessionManager) Len ¶
func (cm *SessionManager) Len() int
func (*SessionManager) Remove ¶
func (cm *SessionManager) Remove(session ISession)
func (*SessionManager) RemoveById ¶
func (cm *SessionManager) RemoveById(sessionID int64)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.