gateway

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsClientClosed

func IsClientClosed(err error) bool

func IsClientNotExist

func IsClientNotExist(err error) bool

func IsIDAlreadyExist added in v1.3.0

func IsIDAlreadyExist(err error) bool

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.

func (*Client) GetInfo

func (c *Client) GetInfo() gate.Info

func (*Client) IsRunning

func (c *Client) IsRunning() bool

IsRunning return true if client is running

func (*Client) Run

func (c *Client) Run()

func (*Client) SetID

func (c *Client) SetID(id gate.ID)

SetID set client id.

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

type Impl struct {
	gate.Gateway
	// contains filtered or unexported fields
}

func NewServer

func NewServer(options *Options) (*Impl, error)

func (*Impl) AddClient

func (c *Impl) AddClient(cs gate.Client)

func (*Impl) EnqueueMessage

func (c *Impl) EnqueueMessage(id gate.ID, msg *messages.GlideMessage) error

EnqueueMessage to the client with the specified id.

func (*Impl) ExitClient

func (c *Impl) ExitClient(id gate.ID) error

ExitClient close the client with the specified id. If the client is not exist, return errClientNotExist.

func (*Impl) IsOnline

func (c *Impl) IsOnline(id gate.ID) bool

func (*Impl) SetClientID

func (c *Impl) SetClientID(oldID, newID gate.ID) error

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)读取消息的读取者, 可以用于定义如何从连接中读取并解析消息.

type Options

type Options struct {
	// ID is the gateway id.
	ID string
	// MaxMessageConcurrency is the max message concurrency.
	MaxMessageConcurrency int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL