Skip to content

Commit 77f09c2

Browse files
committed
netlink: update to lneto BackoffStrategy API
StackRetrying and StackGo now take a lneto.BackoffStrategy function instead of a time.Duration. Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 2abca74 commit 77f09c2

7 files changed

Lines changed: 23 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# espradio
22

3-
[![Build](https://github.com/tinygo-org/espradio/actions/workflows/build.yml/badge.svg)](https://github.com/tinygo-org/espradio/actions/workflows/build.yml)
3+
[![PkgGoDev](https://pkg.go.dev/badge/pkg.go.dev/tinygo.org/x/espradio)](https://pkg.go.dev/tinygo.org/x/espradio) [![Build](https://github.com/tinygo-org/espradio/actions/workflows/build.yml/badge.svg)](https://github.com/tinygo-org/espradio/actions/workflows/build.yml)
44

55
TinyGo package for using the ESP32 onboard radio for wireless communication.
66

doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package espradio provides support for the ESP32-S2 and ESP32-S3 microcontrollers.
2+
// It is based on the ESP-IDF framework and provides access to Wi-Fi and Bluetooth.
3+
// The package is designed to be used with the TinyGo compiler.
4+
package espradio // import "tinygo.org/x/espradio"

espstack.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/netip"
66
"time"
77

8+
"github.com/soypat/lneto"
89
"github.com/soypat/lneto/ethernet"
910
"github.com/soypat/lneto/x/xnet"
1011
)
@@ -110,8 +111,9 @@ func (stack *Stack) SetupWithDHCP(cfg DHCPConfig) (*xnet.DHCPResults, error) {
110111
}
111112

112113
lstack := stack.LnetoStack()
113-
const pollTime = 50 * time.Millisecond
114-
rstack := lstack.StackRetrying(pollTime)
114+
rstack := lstack.StackRetrying(lneto.BackoffStrategy(func(_ uint) time.Duration {
115+
return 50 * time.Millisecond
116+
}))
115117

116118
dhcpResults, err := rstack.DoDHCPv4(reqaddr, 3*time.Second, 3)
117119
if err != nil {

examples/http-app/main-http.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121
"unsafe"
2222

23+
"github.com/soypat/lneto"
2324
"github.com/soypat/lneto/http/httpraw"
2425
"github.com/soypat/lneto/tcp"
2526
"github.com/soypat/lneto/x/xnet"
@@ -106,7 +107,9 @@ func main() {
106107
println("got IP:", dhcp.AssignedAddr.String())
107108

108109
lstack := espstack.LnetoStack()
109-
rstack := lstack.StackRetrying(pollTime)
110+
rstack := lstack.StackRetrying(lneto.BackoffStrategy(func(_ uint) time.Duration {
111+
return pollTime
112+
}))
110113
gatewayHW, err := rstack.DoResolveHardwareAddress6(dhcp.Router, 500*time.Millisecond, 4)
111114
if err != nil {
112115
panic("ARP resolve failed: " + err.Error())

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module tinygo.org/x/espradio
33
go 1.24.4
44

55
require (
6-
github.com/soypat/lneto v0.0.0-20260411230216-9e4da57335e7
6+
github.com/soypat/lneto v0.0.0-20260415000502-16c2c3de36a2
77
tinygo.org/x/drivers v0.34.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/soypat/lneto v0.0.0-20260411230216-9e4da57335e7 h1:eAHkhUeXPf7vCrsOAINeDt3lUUjZA0dJyd9jCxRSUlU=
2-
github.com/soypat/lneto v0.0.0-20260411230216-9e4da57335e7/go.mod h1:g/8Lk+hIsMZydyWDJjK2YfsCuG6jA5mWCO6U+4S7w1U=
1+
github.com/soypat/lneto v0.0.0-20260415000502-16c2c3de36a2 h1:eoExDNiTP/WWWyBH8UOKH7DG/j66ZAY8MLifUAQqULs=
2+
github.com/soypat/lneto v0.0.0-20260415000502-16c2c3de36a2/go.mod h1:g/8Lk+hIsMZydyWDJjK2YfsCuG6jA5mWCO6U+4S7w1U=
33
github.com/soypat/natiu-mqtt v0.6.0 h1:ddrem9iAqFYtQOx2C7AhCizhPXXmGZs1T5fkvLroPO4=
44
github.com/soypat/natiu-mqtt v0.6.0/go.mod h1:xEta+cwop9izVCW7xOx2W+ct9PRMqr0gNVkvBPnQTc4=
55
tinygo.org/x/drivers v0.34.0 h1:lw8ePJeUSn9oICKBvQXHC9TIE+J00OfXfkGTrpXM9Iw=

netlink/netlink.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sync"
99
"time"
1010

11+
"github.com/soypat/lneto"
1112
"github.com/soypat/lneto/x/xnet"
1213

1314
nl "tinygo.org/x/drivers/netlink"
@@ -16,6 +17,10 @@ import (
1617

1718
const pollTime = 5 * time.Millisecond
1819

20+
var pollBackoff = lneto.BackoffStrategy(func(_ uint) time.Duration {
21+
return pollTime
22+
})
23+
1924
// Esplink implements the Netlinker interface for the ESP32-C3's WiFi interface, using the espradio package and an lneto Stack.
2025
type Esplink struct {
2126
params *nl.ConnectParams
@@ -30,7 +35,7 @@ type Esplink struct {
3035
}
3136

3237
func (n *Esplink) rstack() xnet.StackRetrying {
33-
return n.netstack.LnetoStack().StackRetrying(pollTime)
38+
return n.netstack.LnetoStack().StackRetrying(pollBackoff)
3439
}
3540

3641
// NetConnect device to network
@@ -113,7 +118,7 @@ func (n *Esplink) NetConnect(params *nl.ConnectParams) error {
113118
}
114119
n.stackloop.Do(func() {
115120
// Start stack goroutine once.
116-
gostack := n.netstack.LnetoStack().StackGo(pollTime, xnet.StackGoConfig{
121+
gostack := n.netstack.LnetoStack().StackGo(pollBackoff, xnet.StackGoConfig{
117122
ListenerPoolConfig: xnet.TCPPoolConfig{
118123
PoolSize: 2,
119124
QueueSize: 4,

0 commit comments

Comments
 (0)