Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of the MessageChannelDepth value #352

Merged
merged 1 commit into from Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions client.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssl/main.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion filestore.go
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion fvt_client_test.go
Expand Up @@ -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()
}
Expand Down
7 changes: 2 additions & 5 deletions options.go
Expand Up @@ -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),
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions router.go
Expand Up @@ -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] == "#" {
Expand Down
2 changes: 1 addition & 1 deletion topic.go
Expand Up @@ -75,7 +75,7 @@ func validateTopicAndQos(topic string, qos byte) error {
}
}

if qos < 0 || qos > 2 {
if qos > 2 {
return ErrInvalidQos
}
return nil
Expand Down