Skip to content

Commit 782a0f6

Browse files
author
Al S-M
committedAug 29, 2019
Remove use of the MessageChannelDepth value
and fix up some linting issues. eclipse-paho#339
1 parent 8f8de00 commit 782a0f6

File tree

7 files changed

+13
-24
lines changed

7 files changed

+13
-24
lines changed
 

‎client.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ func NewClient(o *ClientOptions) Client {
140140
c.messageIds = messageIds{index: make(map[uint16]tokenCompletor)}
141141
c.msgRouter, c.stopRouter = newRouter()
142142
c.msgRouter.setDefaultHandler(c.options.DefaultPublishHandler)
143-
if !c.options.AutoReconnect {
144-
c.options.MessageChannelDepth = 0
145-
}
143+
146144
return c
147145
}
148146

@@ -210,8 +208,8 @@ func (c *client) Connect() Token {
210208
t := newToken(packets.Connect).(*ConnectToken)
211209
DEBUG.Println(CLI, "Connect()")
212210

213-
c.obound = make(chan *PacketAndToken, c.options.MessageChannelDepth)
214-
c.oboundP = make(chan *PacketAndToken, c.options.MessageChannelDepth)
211+
c.obound = make(chan *PacketAndToken)
212+
c.oboundP = make(chan *PacketAndToken)
215213
c.ibound = make(chan packets.ControlPacket)
216214

217215
go func() {
@@ -306,7 +304,7 @@ func (c *client) Connect() Token {
306304
go keepalive(c)
307305
}
308306

309-
c.incomingPubChan = make(chan *packets.PublishPacket, c.options.MessageChannelDepth)
307+
c.incomingPubChan = make(chan *packets.PublishPacket)
310308
c.msgRouter.matchAndDispatch(c.incomingPubChan, c.options.Order, c)
311309

312310
c.setConnected(connected)
@@ -322,7 +320,7 @@ func (c *client) Connect() Token {
322320
go incoming(c)
323321

324322
// Take care of any messages in the store
325-
if c.options.CleanSession == false {
323+
if !c.options.CleanSession {
326324
c.resume(c.options.ResumeSubs)
327325
} else {
328326
c.persist.Reset()

‎cmd/ssl/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func main() {
113113
c.Subscribe("/go-mqtt/sample", 0, nil)
114114

115115
i := 0
116-
for _ = range time.Tick(time.Duration(1) * time.Second) {
116+
for range time.Tick(time.Duration(1) * time.Second) {
117117
if i == 5 {
118118
break
119119
}

‎filestore.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (store *FileStore) all() []string {
166166
for _, f := range files {
167167
DEBUG.Println(STR, "file in All():", f.Name())
168168
name := f.Name()
169-
if name[len(name)-4:len(name)] != msgExt {
169+
if name[len(name)-4:] != msgExt {
170170
DEBUG.Println(STR, "skipping file, doesn't have right extension: ", name)
171171
continue
172172
}

‎fvt_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ func Test_cleanUpMids(t *testing.T) {
10261026
c.(*client).messageIds.Unlock()
10271027
c.(*client).internalConnLost(fmt.Errorf("cleanup test"))
10281028

1029-
time.Sleep(5 * time.Second)
1029+
time.Sleep(1 * time.Second)
10301030
if !c.IsConnected() {
10311031
t.Fail()
10321032
}

‎options.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func NewClientOptions() *ClientOptions {
111111
OnConnect: nil,
112112
OnConnectionLost: DefaultConnectionLostHandler,
113113
WriteTimeout: 0, // 0 represents timeout disabled
114-
MessageChannelDepth: 100,
115114
ResumeSubs: false,
116115
HTTPHeaders: make(map[string][]string),
117116
}
@@ -327,10 +326,8 @@ func (o *ClientOptions) SetAutoReconnect(a bool) *ClientOptions {
327326
return o
328327
}
329328

330-
// SetMessageChannelDepth sets the size of the internal queue that holds messages while the
331-
// client is temporairily offline, allowing the application to publish when the client is
332-
// reconnecting. This setting is only valid if AutoReconnect is set to true, it is otherwise
333-
// ignored.
329+
// SetMessageChannelDepth DEPRECATED The value set here no longer has any effect, this function
330+
// remains so the API is not altered.
334331
func (o *ClientOptions) SetMessageChannelDepth(s uint) *ClientOptions {
335332
o.MessageChannelDepth = s
336333
return o

‎router.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,11 @@ type route struct {
3737
// and returns a boolean of the outcome
3838
func match(route []string, topic []string) bool {
3939
if len(route) == 0 {
40-
if len(topic) == 0 {
41-
return true
42-
}
43-
return false
40+
return len(topic) == 0
4441
}
4542

4643
if len(topic) == 0 {
47-
if route[0] == "#" {
48-
return true
49-
}
50-
return false
44+
return route[0] == "#"
5145
}
5246

5347
if route[0] == "#" {

‎topic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func validateTopicAndQos(topic string, qos byte) error {
7575
}
7676
}
7777

78-
if qos < 0 || qos > 2 {
78+
if qos > 2 {
7979
return ErrInvalidQos
8080
}
8181
return nil

0 commit comments

Comments
 (0)
Please sign in to comment.