session

package
v0.0.0-...-a01428d Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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 创建通道 通过网络层接口进行数据通讯

func (*Channel) Close

func (this *Channel) Close()

安全退出

func (*Channel) IsStop

func (this *Channel) IsStop() bool

func (*Channel) Read

func (this *Channel) Read(p []byte) (n int, err error)

func (*Channel) Send

func (this *Channel) Send(msg packets.ControlPacket) (err error)

Send 将消息写入发送channel 如果channel的buffer满后,会阻塞

func (*Channel) Start

func (this *Channel) Start()

func (*Channel) Write

func (this *Channel) Write(p []byte) (n int, err error)

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) Error

func (b *ConnectToken) Error() error

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

func (b *ConnectToken) WaitTimeout(d time.Duration) bool

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) Error

func (b *DisconnectToken) Error() error

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

func (b *DisconnectToken) WaitTimeout(d time.Duration) bool

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) Error

func (b *PublishToken) Error() error

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

func (b *PublishToken) WaitTimeout(d time.Duration) bool

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 SentChan

type SentChan chan *SendData

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) Close

func (this *Session) Close()

关闭

func (*Session) GetKeepalive

func (this *Session) GetKeepalive() int64

func (*Session) IsClosed

func (this *Session) IsClosed() bool

判断是否已经关闭

func (*Session) IsConnected

func (this *Session) IsConnected() bool

判断是否已经连接成功 看CONNECT消息有没有处理完成 如果IsClosed返回true,那么IsConnected一定返回true

func (*Session) OnChannelError

func (this *Session) OnChannelError(err error)

func (*Session) OnTick

func (this *Session) OnTick()

定时被调用,用于检查各种超时

func (*Session) Ping

func (this *Session) Ping()

发送ping消息

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 (this *Session) SetClientId(id string)

func (*Session) SetKeepalive

func (this *Session) SetKeepalive(keepalive int64)

func (*Session) SetOnDisconnected

func (this *Session) SetOnDisconnected(cb func())

func (*Session) SetOnMessage

func (this *Session) SetOnMessage(cb func(*packets.PublishPacket))

type SessionInfo

type SessionInfo struct {
	Id string
	//等待发送的消息数
	PeddingMsgCnt int
	//正在发送中的消息数
	InflightMsgCnt int
	//在Channel发送队列中的包数
	SendingMsgCnt int
}

type SessionList

type SessionList struct {
	Active   []string
	Inactive []string
}

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) Error

func (b *SubscribeToken) Error() error

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

func (b *SubscribeToken) WaitTimeout(d time.Duration) bool

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) Error

func (b *UnsubscribeToken) Error() error

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

func (b *UnsubscribeToken) WaitTimeout(d time.Duration) bool

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

Jump to

Keyboard shortcuts

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