From 782a0f6f87cc9dedb511cbfa8ea6f064590d7836 Mon Sep 17 00:00:00 2001 From: Al S-M Date: Thu, 29 Aug 2019 13:55:43 +0100 Subject: [PATCH] Remove use of the MessageChannelDepth value and fix up some linting issues. #339 --- client.go | 12 +++++------- cmd/ssl/main.go | 2 +- filestore.go | 2 +- fvt_client_test.go | 2 +- options.go | 7 ++----- router.go | 10 ++-------- topic.go | 2 +- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/client.go b/client.go index 485fa342..ece3d6a0 100644 --- a/client.go +++ b/client.go @@ -140,9 +140,7 @@ func NewClient(o *ClientOptions) Client { c.messageIds = messageIds{index: make(map[uint16]tokenCompletor)} c.msgRouter, c.stopRouter = newRouter() c.msgRouter.setDefaultHandler(c.options.DefaultPublishHandler) - if !c.options.AutoReconnect { - c.options.MessageChannelDepth = 0 - } + return c } @@ -210,8 +208,8 @@ func (c *client) Connect() Token { t := newToken(packets.Connect).(*ConnectToken) DEBUG.Println(CLI, "Connect()") - c.obound = make(chan *PacketAndToken, c.options.MessageChannelDepth) - c.oboundP = make(chan *PacketAndToken, c.options.MessageChannelDepth) + c.obound = make(chan *PacketAndToken) + c.oboundP = make(chan *PacketAndToken) c.ibound = make(chan packets.ControlPacket) go func() { @@ -306,7 +304,7 @@ func (c *client) Connect() Token { go keepalive(c) } - c.incomingPubChan = make(chan *packets.PublishPacket, c.options.MessageChannelDepth) + c.incomingPubChan = make(chan *packets.PublishPacket) c.msgRouter.matchAndDispatch(c.incomingPubChan, c.options.Order, c) c.setConnected(connected) @@ -322,7 +320,7 @@ func (c *client) Connect() Token { go incoming(c) // Take care of any messages in the store - if c.options.CleanSession == false { + if !c.options.CleanSession { c.resume(c.options.ResumeSubs) } else { c.persist.Reset() diff --git a/cmd/ssl/main.go b/cmd/ssl/main.go index 99d4eae8..e7c76729 100644 --- a/cmd/ssl/main.go +++ b/cmd/ssl/main.go @@ -113,7 +113,7 @@ func main() { c.Subscribe("/go-mqtt/sample", 0, nil) i := 0 - for _ = range time.Tick(time.Duration(1) * time.Second) { + for range time.Tick(time.Duration(1) * time.Second) { if i == 5 { break } diff --git a/filestore.go b/filestore.go index c4a0d36b..0d8f910e 100644 --- a/filestore.go +++ b/filestore.go @@ -166,7 +166,7 @@ func (store *FileStore) all() []string { for _, f := range files { DEBUG.Println(STR, "file in All():", f.Name()) name := f.Name() - if name[len(name)-4:len(name)] != msgExt { + if name[len(name)-4:] != msgExt { DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name) continue } diff --git a/fvt_client_test.go b/fvt_client_test.go index f22a73ff..94d7ab78 100644 --- a/fvt_client_test.go +++ b/fvt_client_test.go @@ -1026,7 +1026,7 @@ func Test_cleanUpMids(t *testing.T) { c.(*client).messageIds.Unlock() c.(*client).internalConnLost(fmt.Errorf("cleanup test")) - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) if !c.IsConnected() { t.Fail() } diff --git a/options.go b/options.go index f827bcf7..f8a0c3e4 100644 --- a/options.go +++ b/options.go @@ -111,7 +111,6 @@ func NewClientOptions() *ClientOptions { OnConnect: nil, OnConnectionLost: DefaultConnectionLostHandler, WriteTimeout: 0, // 0 represents timeout disabled - MessageChannelDepth: 100, ResumeSubs: false, HTTPHeaders: make(map[string][]string), } @@ -327,10 +326,8 @@ func (o *ClientOptions) SetAutoReconnect(a bool) *ClientOptions { return o } -// SetMessageChannelDepth sets the size of the internal queue that holds messages while the -// client is temporairily offline, allowing the application to publish when the client is -// reconnecting. This setting is only valid if AutoReconnect is set to true, it is otherwise -// ignored. +// SetMessageChannelDepth DEPRECATED The value set here no longer has any effect, this function +// remains so the API is not altered. func (o *ClientOptions) SetMessageChannelDepth(s uint) *ClientOptions { o.MessageChannelDepth = s return o diff --git a/router.go b/router.go index 7b4e8f80..2903efc2 100644 --- a/router.go +++ b/router.go @@ -37,17 +37,11 @@ type route struct { // and returns a boolean of the outcome func match(route []string, topic []string) bool { if len(route) == 0 { - if len(topic) == 0 { - return true - } - return false + return len(topic) == 0 } if len(topic) == 0 { - if route[0] == "#" { - return true - } - return false + return route[0] == "#" } if route[0] == "#" { diff --git a/topic.go b/topic.go index 6fa3ad2a..701c841c 100644 --- a/topic.go +++ b/topic.go @@ -75,7 +75,7 @@ func validateTopicAndQos(topic string, qos byte) error { } } - if qos < 0 || qos > 2 { + if qos > 2 { return ErrInvalidQos } return nil