Documentation ¶
Index ¶
- type BaseRouter
- type Config
- type ConnManager
- type Connection
- func (c *Connection) GetConnID() uint32
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetTCPConnection() *net.TCPConn
- func (c *Connection) RemoteAddr() net.Addr
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendBuffMessage(id uint32, data []byte) error
- func (c *Connection) SendMessage(id 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 HandFunc
- type IConnManager
- type IConnection
- type IMessage
- type IMessageHandle
- type IPack
- type IRequest
- type IRouter
- type IServer
- type Message
- type MessageHandle
- type Pack
- type Request
- type Server
- func (s *Server) AddRouter(id uint32, r IRouter)
- func (s *Server) CallOnConnStart(conn IConnection)
- func (s *Server) CallOnConnStop(conn IConnection)
- func (s *Server) Close()
- func (s *Server) GetConnManager() IConnManager
- func (s *Server) Serve()
- func (s *Server) SetOnConnStart(f func(IConnection))
- func (s *Server) SetOnConnStop(f func(IConnection))
- func (s *Server) Start()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseRouter ¶
type BaseRouter struct { }
func (*BaseRouter) AfterHook ¶
func (b *BaseRouter) AfterHook(req IRequest)
func (*BaseRouter) BeforeHook ¶
func (b *BaseRouter) BeforeHook(req IRequest)
func (*BaseRouter) Handle ¶
func (b *BaseRouter) Handle(req IRequest)
type Config ¶
type Config struct { Name string `json:"name"` Host string `json:"host"` TCPPort int `json:"port"` Version string `json:"version"` MaxPacketSize uint32 `json:"max_packet_size"` MaxConn int `json:"max_conn"` WorkerPoolSize uint32 `json:"worker_pool_size"` MaxWorkerTaskLen uint32 `json:"max_worker_task_len"` MaxMessageChanLen uint32 `json:"max_message_chan_len"` Raft struct { Id string `json:"id"` Addr string `json:"addr"` Cluster string `json:"cluster"` } `json:"raft"` }
var Setting *Config
type ConnManager ¶
type ConnManager struct {
// contains filtered or unexported fields
}
func NewConnManager ¶
func NewConnManager() *ConnManager
func (*ConnManager) Add ¶
func (c *ConnManager) Add(conn IConnection)
func (*ConnManager) ClearConn ¶
func (c *ConnManager) ClearConn()
func (*ConnManager) Get ¶
func (c *ConnManager) Get(id uint32) (IConnection, error)
func (*ConnManager) Len ¶
func (c *ConnManager) Len() int
func (*ConnManager) Remove ¶
func (c *ConnManager) Remove(conn IConnection)
type Connection ¶
type Connection struct { TCPServer IServer Conn *net.TCPConn ConnID uint32 ExitBuffChan chan bool // contains filtered or unexported fields }
func NewConnection ¶
func NewConnection(server IServer, conn *net.TCPConn, connID uint32, h IMessageHandle) *Connection
func (*Connection) GetConnID ¶
func (c *Connection) GetConnID() uint32
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
func (*Connection) GetTCPConnection ¶
func (c *Connection) GetTCPConnection() *net.TCPConn
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() net.Addr
func (*Connection) RemoveProperty ¶
func (c *Connection) RemoveProperty(key string)
func (*Connection) SendBuffMessage ¶
func (c *Connection) SendBuffMessage(id uint32, data []byte) error
func (*Connection) SendMessage ¶
func (c *Connection) SendMessage(id uint32, data []byte) error
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
func (*Connection) Start ¶
func (c *Connection) Start()
func (*Connection) StartReader ¶
func (c *Connection) StartReader()
func (*Connection) StartWriter ¶
func (c *Connection) StartWriter()
func (*Connection) Stop ¶
func (c *Connection) Stop()
type IConnManager ¶
type IConnManager interface { Add(IConnection) Remove(IConnection) Get(uint32) (IConnection, error) Len() int ClearConn() }
type IConnection ¶
type IMessageHandle ¶
type IRequest ¶
type IRequest interface { GetConnection() IConnection GetData() []byte GetMessageID() uint32 }
type IServer ¶
type IServer interface { Start() Close() Serve() AddRouter(uint32, IRouter) GetConnManager() IConnManager SetOnConnStart(func(IConnection)) SetOnConnStop(func(IConnection)) CallOnConnStart(IConnection) CallOnConnStop(IConnection) }
type MessageHandle ¶
type MessageHandle struct { APIs map[uint32]IRouter WorkerPoolSize uint32 TaskQueue []chan IRequest }
func NewMessageHandle ¶
func NewMessageHandle() *MessageHandle
func (*MessageHandle) AddRouter ¶
func (m *MessageHandle) AddRouter(id uint32, router IRouter)
func (*MessageHandle) DoMessageHandler ¶
func (m *MessageHandle) DoMessageHandler(req IRequest)
func (*MessageHandle) SendMessageToTaskQueue ¶
func (m *MessageHandle) SendMessageToTaskQueue(req IRequest)
func (*MessageHandle) StartOneWorker ¶
func (m *MessageHandle) StartOneWorker(workerID int, taskQueue chan IRequest)
func (*MessageHandle) StartWorkerPool ¶
func (m *MessageHandle) StartWorkerPool()
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (Request) GetConnection ¶
func (r Request) GetConnection() IConnection
func (*Request) GetMessageID ¶
type Server ¶
type Server struct { Name string IPVersion string IP string Port int ConnManager IConnManager OnConnStart func(conn IConnection) OnConnStop func(conn IConnection) // contains filtered or unexported fields }
func (*Server) CallOnConnStart ¶
func (s *Server) CallOnConnStart(conn IConnection)
func (*Server) CallOnConnStop ¶
func (s *Server) CallOnConnStop(conn IConnection)
func (*Server) GetConnManager ¶
func (s *Server) GetConnManager() IConnManager
func (*Server) SetOnConnStart ¶
func (s *Server) SetOnConnStart(f func(IConnection))
func (*Server) SetOnConnStop ¶
func (s *Server) SetOnConnStop(f func(IConnection))
Click to show internal directories.
Click to hide internal directories.