Documentation ¶
Index ¶
- type Channel
- type ConnectToken
- type DisconnectReason
- type DisconnectToken
- type PacketAndToken
- type PublishToken
- type SendData
- type SentChan
- type Session
- func (this *Session) BroadcastSessionInfo()
- func (this *Session) Close()
- func (this *Session) GetKeepalive() int64
- func (this *Session) IsClosed() bool
- func (this *Session) IsConnected() bool
- func (this *Session) OnChannelError(err error)
- func (this *Session) OnTick()
- func (this *Session) Ping()
- func (this *Session) Publish(msg *packets.PublishPacket) (token Token, err error)
- func (this *Session) RecvMsg(msg packets.ControlPacket)
- func (this *Session) Send(msg packets.ControlPacket) (token Token, err error)
- func (this *Session) SetClientId(id string)
- func (this *Session) SetKeepalive(keepalive int64)
- func (this *Session) SetOnDisconnected(cb func())
- func (this *Session) SetOnMessage(cb func(*packets.PublishPacket))
- type SessionInfo
- type SessionList
- type SessionMgr
- type SubscribeToken
- type Token
- type UnsubscribeToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func NewChannel ¶
func NewChannel(c io.ReadWriteCloser, session *Session) *Channel
New 创建通道 通过网络层接口进行数据通讯
type ConnectToken ¶
type ConnectToken struct {
// contains filtered or unexported fields
}
ConnectToken is an extension of Token containing the extra fields required to provide information about calls to Connect()
func (*ConnectToken) ReturnCode ¶
func (c *ConnectToken) ReturnCode() byte
ReturnCode returns the acknowlegement code in the connack sent in response to a Connect()
func (*ConnectToken) Wait ¶
func (b *ConnectToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*ConnectToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type DisconnectReason ¶
type DisconnectReason int32
const ( //没有异常断开 DISERR_OK DisconnectReason = 0 //发送异常 DISERR_SENT DisconnectReason = 1 //接收异常 DISERR_RECV DisconnectReason = 2 //PING超时 DISERR_PING_TIMEOUT DisconnectReason = 3 )
func (DisconnectReason) Error ¶
func (dr DisconnectReason) Error() string
type DisconnectToken ¶
type DisconnectToken struct {
// contains filtered or unexported fields
}
DisconnectToken is an extension of Token containing the extra fields required to provide information about calls to Disconnect()
func (*DisconnectToken) Wait ¶
func (b *DisconnectToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*DisconnectToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type PacketAndToken ¶
type PacketAndToken struct {
// contains filtered or unexported fields
}
PacketAndToken is a struct that contains both a ControlPacket and a Token. This struct is passed via channels between the client interface code and the underlying code responsible for sending and receiving MQTT messages.
type PublishToken ¶
type PublishToken struct {
// contains filtered or unexported fields
}
PublishToken is an extension of Token containing the extra fields required to provide information about calls to Publish()
func (*PublishToken) MessageID ¶
func (p *PublishToken) MessageID() uint16
MessageID returns the MQTT message ID that was assigned to the Publish packet when it was sent to the broker
func (*PublishToken) Wait ¶
func (b *PublishToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*PublishToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type SendData ¶
type SendData struct { Msg packets.ControlPacket Result chan<- error }
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
通道要保存服务端mqtt会话数据,比如tipic过滤器等
func NewSession ¶
func NewSession(mgr SessionMgr, conn io.ReadWriteCloser, isServer bool) *Session
创建会话 客户端会话和服务端会议的主要区别只是要不要发ping消息
func (*Session) BroadcastSessionInfo ¶
func (this *Session) BroadcastSessionInfo()
由独立的协程调用,注意共享数据访问
func (*Session) GetKeepalive ¶
func (*Session) IsConnected ¶
判断是否已经连接成功 看CONNECT消息有没有处理完成 如果IsClosed返回true,那么IsConnected一定返回true
func (*Session) OnChannelError ¶
func (*Session) Publish ¶
func (this *Session) Publish(msg *packets.PublishPacket) (token Token, err error)
外部让session发布消息 函数返回时,表示session runtine已经在处理了 最终处理结果通过chan来接收,可以忽略结果 qos=0时,session发送完数据就有结果 qos=1时,session收到PUBACK后才有结果 qos=2时, session收到PUBCOMP后才有结果
func (*Session) RecvMsg ¶
func (this *Session) RecvMsg(msg packets.ControlPacket)
func (*Session) Send ¶
func (this *Session) Send(msg packets.ControlPacket) (token Token, err error)
func (*Session) SetClientId ¶
func (*Session) SetKeepalive ¶
func (*Session) SetOnDisconnected ¶
func (this *Session) SetOnDisconnected(cb func())
func (*Session) SetOnMessage ¶
func (this *Session) SetOnMessage(cb func(*packets.PublishPacket))
type SessionInfo ¶
type SessionList ¶
type SessionMgr ¶
type SessionMgr interface { HandleConnection(session *Session) OnConnected(session *Session) OnConnectTimeout(session *Session) OnPingTimeout(session *Session) OnDisconnected(session *Session) DisconectSessionByClientId(clientId string) GetSubscriptionMgr() topic.SubscriptionMgr GetSessions() SessionList GetStoreMgr() store.StoreMgr BroadcastSessionInfo(session *Session) //给包外部调用 Publish(topic string, msg []byte, qos byte) error }
func GetMgr ¶
func GetMgr() SessionMgr
type SubscribeToken ¶
type SubscribeToken struct {
// contains filtered or unexported fields
}
SubscribeToken is an extension of Token containing the extra fields required to provide information about calls to Subscribe()
func (*SubscribeToken) Result ¶
func (s *SubscribeToken) Result() map[string]byte
Result returns a map of topics that were subscribed to along with the matching return code from the broker. This is either the Qos value of the subscription or an error code.
func (*SubscribeToken) Wait ¶
func (b *SubscribeToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*SubscribeToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type Token ¶
type Token interface { Wait() bool WaitTimeout(time.Duration) bool Error() error // contains filtered or unexported methods }
Token defines the interface for the tokens used to indicate when actions have completed.
type UnsubscribeToken ¶
type UnsubscribeToken struct {
// contains filtered or unexported fields
}
UnsubscribeToken is an extension of Token containing the extra fields required to provide information about calls to Unsubscribe()
func (*UnsubscribeToken) Wait ¶
func (b *UnsubscribeToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*UnsubscribeToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again