Documentation ¶
Index ¶
- Variables
- type Client
- func (cl *Client) ClearBuffers()
- func (cl *Client) ForgetSubscription(filter string)
- func (cl *Client) Identify(lid string, pk packets.Packet, ac auth.Controller)
- func (cl *Client) Info() events.Client
- func (cl *Client) NextPacketID() uint32
- func (cl *Client) NoteSubscription(filter string, qos byte)
- func (cl *Client) Read(packetHandler func(*Client, packets.Packet) error) error
- func (cl *Client) ReadFixedHeader(fh *packets.FixedHeader) error
- func (cl *Client) ReadPacket(fh *packets.FixedHeader) (pk packets.Packet, err error)
- func (cl *Client) Start()
- func (cl *Client) Stop(err error)
- func (cl *Client) StopCause() error
- func (cl *Client) WritePacket(pk packets.Packet) (n int, err error)
- type Clients
- type Inflight
- type InflightMessage
- type LWT
- type State
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConnectionClosed is returned when operating on a closed // connection and/or when no error cause has been given. ErrConnectionClosed = errors.New("connection not open") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { State State // 客户端的运行状态. LWT LWT // 遗言. Inflight *Inflight // 正在处理的消息. sync.RWMutex // 读写锁 Username []byte // 用户名. AC auth.Controller // 授权控制器 Listener string // websocket 还是 tcp的. ID string // 客户端唯一标识. R *circ.Reader // 入流. W *circ.Writer // 出流. Subscriptions topics.Subscriptions // 订阅列表. CleanSession bool // 是否清楚会话 // contains filtered or unexported fields }
客户端的状态
func NewClientStub ¶
NewClientStub returns an instance of Client with basic initializations. This method is typically called by the persistence restoration system.
func (*Client) ClearBuffers ¶
func (cl *Client) ClearBuffers()
ClearBuffers sets the read/write buffers to nil so they can be deallocated automatically when no longer in use.
func (*Client) ForgetSubscription ¶
ForgetSubscription forgests a subscription note for the client.
func (*Client) NextPacketID ¶
NextPacketID returns the next packet id for a client, looping back to 0 if the maximum ID has been reached.
func (*Client) NoteSubscription ¶
NoteSubscription makes a note of a subscription for the client.
func (*Client) Read ¶
Read loops forever reading new packets from a client connection until an error is encountered (or the connection is closed).
func (*Client) ReadFixedHeader ¶
func (cl *Client) ReadFixedHeader(fh *packets.FixedHeader) error
ReadFixedHeader reads in the values of the next packet's fixed header.
func (*Client) ReadPacket ¶
ReadPacket 将剩余的缓冲区读取到 MQTT 数据包中。
func (*Client) Start ¶
func (cl *Client) Start()
Start begins the client goroutines reading and writing packets.
func (*Client) Stop ¶
Stop instructs the client to shut down all processing goroutines and disconnect. A cause error may be passed to identfy the reason for stopping.
type Clients ¶
Clients contains a map of the clients known by the broker.
func (*Clients) GetByListener ¶
GetByListener returns clients matching a listener id.
type Inflight ¶
Inflight is a map of InflightMessage keyed on packet id.
type InflightMessage ¶
type InflightMessage struct { Packet packets.Packet // 正在处理的消息. Sent int64 // 上次重发时间. Created int64 // 消息创建时间 Resends int // 消息被重新发送了多少次. }
InflightMessage contains data about a packet which is currently in-flight.