Documentation
¶
Index ¶
- type BootStraper
- type Config
- type ConnManage
- 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) SendBuffMsg(msgId uint32, data []byte) error
- func (c *Connection) SendMsg(msgId uint32, data []byte) error
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) Stop()
- type Connectioner
- type Context
- type DataPack
- type LogLevel
- type LogWrite
- type Logger
- type Message
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BootStraper ¶
type BootStraper interface {
Listen() // start server
Stop() // stop server
GetConnMgr() ConnManager // get connection manager
SetOnConnStart(func(conn Connectioner)) // set hook func when client connect server
SetOnConnClose(func(conn Connectioner)) // set hook func when client disconnect server
CallOnConnStart(conn Connectioner) // call OnConnStart hook func
CallOnConnClose(conn Connectioner) // call OnConnStop hook func
SetLogging(Logger) // set logging
AddRoute(msgId uint32, handleFunc func(ctx *Context)) // add route
Logging() Logger // logging
GetConfig() *Config // get server global config
}
func NewBootStrap ¶
func NewBootStrap(config *Config) BootStraper
type Config ¶
type Config struct {
Name string // server name
IP string // server listen ip
IPVersion string // ip version
Port int // server listen port
MaxPacketSize uint32 // server accept max packet size
MaxConn int // server accept max connection count
WorkerPoolSize uint32 // work pool
MaxWorkerTaskLen uint32 // 业务工作Worker对应负责的任务队列最大任务存储数量
MaxMsgChanLen uint32 // SendBuffMsg发送消息的缓冲最大长度
}
type ConnManage ¶
type ConnManage struct {
// contains filtered or unexported fields
}
func NewConnManage ¶
func NewConnManage() *ConnManage
func (*ConnManage) ClearConn ¶
func (c *ConnManage) ClearConn()
ClearConn stop all connections, then delete them
func (*ConnManage) Get ¶
func (c *ConnManage) Get(connID uint32) (Connectioner, error)
Get get connection by connection id
type ConnManager ¶
type ConnManager interface {
Add(conn Connectioner) // add connection
Remove(conn Connectioner) // delete connection
Get(connID uint32) (Connectioner, error) // get connection by connection id
Len() int // get connections' count
ClearConn() // stop all connections, then delete them
}
type Connection ¶
type Connection struct {
Server BootStraper
Conn *net.TCPConn
ConnID uint32
sync.RWMutex // RWLock
// contains filtered or unexported fields
}
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) SendBuffMsg ¶
func (c *Connection) SendBuffMsg(msgId uint32, data []byte) error
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
func (*Connection) Start ¶
func (c *Connection) Start()
func (*Connection) Stop ¶
func (c *Connection) Stop()
type Connectioner ¶
type Connectioner interface {
Start() // start connection work
Stop() // stop and close connection
GetTCPConnection() *net.TCPConn // 从当前连接获取原始的socket TCPConn
GetConnID() uint32 // get connection's id
RemoteAddr() net.Addr // get remote client addr info
SendMsg(msgId uint32, data []byte) error // 直接将Message数据发送数据给远程的TCP客户端(无缓冲)
SendBuffMsg(msgId uint32, data []byte) error // 直接将Message数据发送给远程的TCP客户端(有缓冲)
SetProperty(key string, value interface{}) // set connection's property
GetProperty(key string) (interface{}, error) // get connection's property
RemoveProperty(key string) // delete connection's property
}
func NewConnection ¶
func NewConnection(server BootStraper, conn *net.TCPConn, connID uint32, route router) Connectioner
NewConnection get new connection instance
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) GetConnection ¶
func (ctx *Context) GetConnection() Connectioner
func (*Context) GetMsgData ¶
type DataPack ¶
type DataPack struct{}
func (*DataPack) GetHeadLen ¶
GetHeadLen get pack head's length
type Logger ¶
type Message ¶
type Message struct {
DataLen uint32 // message's length
Id uint32 // message's id
Data []byte // message's content
}
func NewMsgPackage ¶
NewMsgPackage create a message package instance
func (*Message) GetDataLen ¶
GetDataLen get message data's length
Click to show internal directories.
Click to hide internal directories.