Documentation ¶
Index ¶
- func IsClientClosed(err error) bool
- func IsClientNotExist(err error) bool
- func IsIDAlreadyExist(err error) bool
- func SetMessageReader(s MessageReader)
- type Client
- type ClientConfig
- type Impl
- func (c *Impl) AddClient(cs gate.Client)
- func (c *Impl) EnqueueMessage(id gate.ID, msg *messages.GlideMessage) error
- func (c *Impl) ExitClient(id gate.ID) error
- func (c *Impl) IsOnline(id gate.ID) bool
- func (c *Impl) SetClientID(oldID, newID gate.ID) error
- func (c *Impl) SetMessageHandler(h gate.MessageHandler)
- type MessageReader
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientClosed ¶
func IsClientNotExist ¶
func IsIDAlreadyExist ¶ added in v1.3.0
IsIDAlreadyExist returns true if the error is caused by the ID of the client already exist. Returns when SetClientID is called with the existing new ID.
func SetMessageReader ¶
func SetMessageReader(s MessageReader)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represent a user conn client.
func NewClient ¶
func NewClient(conn conn.Connection, mgr gate.Gateway, handler gate.MessageHandler) *Client
func NewClientWithConfig ¶ added in v1.2.4
func NewClientWithConfig(conn conn.Connection, mgr gate.Gateway, handler gate.MessageHandler, config *ClientConfig) *Client
func (*Client) EnqueueMessage ¶
func (c *Client) EnqueueMessage(msg *messages.GlideMessage) error
EnqueueMessage enqueue message to client message queue.
func (*Client) Exit ¶
func (c *Client) Exit()
Exit client, note: exit client will not close conn right now, but will close when message chan is empty. It's close read right now, and close write2Conn when all message in queue is sent.
type ClientConfig ¶ added in v1.2.4
type ClientConfig struct { // ClientHeartbeatDuration is the duration of heartbeat. ClientHeartbeatDuration time.Duration // ServerHeartbeatDuration is the duration of server heartbeat. ServerHeartbeatDuration time.Duration // HeartbeatLostLimit is the max lost heartbeat count. HeartbeatLostLimit int // CloseImmediately true express when client exit, discard all message in queue, and close connection immediately, // otherwise client will close runRead, and mark as stateClosing, the client cannot receive and enqueue message, // after all message in queue is sent, client will close runWrite and connection. CloseImmediately bool }
ClientConfig client config
type Impl ¶
func (*Impl) EnqueueMessage ¶
EnqueueMessage to the client with the specified id.
func (*Impl) ExitClient ¶
ExitClient close the client with the specified id. If the client is not exist, return errClientNotExist.
func (*Impl) SetClientID ¶
SetClientID replace the oldID with newID of the client. If the oldID is not exist, return errClientNotExist. If the newID is existed, return errClientAlreadyExist.
func (*Impl) SetMessageHandler ¶ added in v1.3.0
func (c *Impl) SetMessageHandler(h gate.MessageHandler)
type MessageReader ¶
type MessageReader interface { // Read 阻塞读取, 会阻塞当前协程 Read(conn conn.Connection) (*messages.GlideMessage, error) // ReadCh 返回两个管道, 第一个用于读取内容, 第二个用于发送停止读取, 停止读取时切记要发送停止信号 ReadCh(conn conn.Connection) (<-chan *readerRes, chan<- interface{}) }
MessageReader 表示一个从连接中(Connection)读取消息的读取者, 可以用于定义如何从连接中读取并解析消息.