mirror of
https://github.com/soypat/lneto.git
synced 2026-07-26 10:38:47 +00:00
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:
@@ -281,6 +281,7 @@ func run() (err error) {
|
||||
RxBuf: make([]byte, mtu),
|
||||
TxBuf: make([]byte, mtu),
|
||||
TxPacketQueueSize: 3,
|
||||
RWBackoff: tcpBackoff,
|
||||
})
|
||||
|
||||
timeHTTPCreate := timer("create HTTP GET request")
|
||||
@@ -393,3 +394,14 @@ 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user