lneto rework: Require explicit BackoffStrategy in all APIs (#116)

* make backoff explicit API

* fix tests to use explicit backoff

* fix examples with explicit tcp
This commit is contained in:
Pat Whittingslow
2026-06-09 10:20:40 -03:00
committed by GitHub
parent 3b82cefec3
commit 6ba06acdcb
28 changed files with 324 additions and 84 deletions
+13
View File
@@ -232,6 +232,7 @@ func run() (err error) {
RxBuf: make([]byte, mtu),
TxBuf: make([]byte, mtu),
TxPacketQueueSize: 3,
RWBackoff: tcpBackoff,
})
err = stack.ListenTCP4(&conn, svPort)
if err != nil {
@@ -363,3 +364,15 @@ func stackBackoff(consecutiveBackoffs uint) time.Duration {
}
return 10 * time.Millisecond
}
func tcpBackoff(consecutiveBackoffs uint) time.Duration {
const (
minWait = uint32(time.Microsecond)
maxWait = 5 * uint32(time.Millisecond)
maxShift = 22
_overflowCheck = minWait << maxShift
)
shifted := minWait << min(consecutiveBackoffs, maxShift)
wait := min(shifted, maxWait)
return time.Duration(wait)
}