mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-09-04 13:59:00 +00:00
MQTT: adds keepalive pinging, disconnect, and graceful goroutine cleanup
This commit is contained in:
+18
-1
@@ -210,7 +210,7 @@ type ClientOptions struct {
|
||||
|
||||
// NewClientOptions returns a new ClientOptions struct.
|
||||
func NewClientOptions() *ClientOptions {
|
||||
return &ClientOptions{Adaptor: net.ActiveDevice, ProtocolVersion: 4}
|
||||
return &ClientOptions{Adaptor: net.ActiveDevice, ProtocolVersion: 4, KeepAlive: 60, PingTimeout: time.Second * 10}
|
||||
}
|
||||
|
||||
// AddBroker adds a broker URI to the list of brokers to be used. The format should be
|
||||
@@ -257,6 +257,23 @@ func (o *ClientOptions) SetPassword(p string) *ClientOptions {
|
||||
return o
|
||||
}
|
||||
|
||||
// SetKeepAlive will set the amount of time (in seconds) that the client
|
||||
// should wait before sending a PING request to the broker. This will
|
||||
// allow the client to know that a connection has not been lost with the
|
||||
// server.
|
||||
func (o *ClientOptions) SetKeepAlive(k time.Duration) *ClientOptions {
|
||||
o.KeepAlive = int64(k / time.Second)
|
||||
return o
|
||||
}
|
||||
|
||||
// SetPingTimeout will set the amount of time (in seconds) that the client
|
||||
// will wait after sending a PING request to the broker, before deciding
|
||||
// that the connection has been lost. Default is 10 seconds.
|
||||
func (o *ClientOptions) SetPingTimeout(k time.Duration) *ClientOptions {
|
||||
o.PingTimeout = k
|
||||
return o
|
||||
}
|
||||
|
||||
// SetWill accepts a string will message to be set. When the client connects,
|
||||
// it will give this will message to the broker, which will then publish the
|
||||
// provided payload (the will) to any clients that are subscribed to the provided
|
||||
|
||||
Reference in New Issue
Block a user