Skip to content

Commit 3570064

Browse files
committed
Connect.Will also returns delay
1 parent 562ed10 commit 3570064

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on http://keepachangelog.com/en/1.0.0/
55
and this project adheres to http://semver.org/spec/v2.0.0.html.
66

7+
## [0.28.1-dev]
8+
9+
- Connect.Will returns WillDelayInterval delay
10+
711
## [0.28.0] 2024-09-21
812

913
- Fix Subscribe.subscriptionID is optional

connect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func (p *Connect) SetWill(will *Publish, delayInterval uint32) {
7575
p.setWillQoS(will.QoS())
7676
}
7777

78-
func (p *Connect) Will() *Publish {
79-
return p.will
78+
func (p *Connect) Will() (*Publish, time.Duration) {
79+
return p.will, time.Duration(p.willDelayInterval) * time.Second
8080
}
8181

8282
func (p *Connect) HasFlag(v byte) bool { return p.flags.Has(v) }

connect_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"regexp"
1010
"strings"
1111
"testing"
12+
"time"
1213

1314
"github.com/eclipse/paho.golang/packets"
1415
"github.com/gregoryv/asserter"
@@ -72,7 +73,7 @@ func TestConnect(t *testing.T) {
7273
if got := c.String(); !strings.Contains(got, "CONNECT") {
7374
t.Error(got)
7475
}
75-
if v := c.Will(); v != nil {
76+
if v, _ := c.Will(); v != nil {
7677
t.Error("no will was set but got", v)
7778
}
7879
testControlPacket(t, c)
@@ -191,7 +192,7 @@ func TestCompareConnect(t *testing.T) {
191192
//p.SetCorrelationData([]byte("11-22-33")) doesn't work in paho
192193
our.SetWill(p, 3)
193194
}
194-
will := our.Will()
195+
will, delay := our.Will()
195196
the.WillRetain = will.Retain()
196197
the.WillFlag = our.HasFlag(WillFlag)
197198
the.WillTopic = will.TopicName()
@@ -205,7 +206,7 @@ func TestCompareConnect(t *testing.T) {
205206
Key: "connected",
206207
Value: "2022-01-01 14:44:32",
207208
})
208-
wExp := uint32(3) // seconds
209+
wExp := uint32(delay / time.Second) // seconds
209210
the.WillProperties.WillDelayInterval = &wExp
210211

211212
// possible bug in Properties.Pack

0 commit comments

Comments
 (0)