mirror of
https://github.com/soypat/lneto.git
synced 2026-09-01 12:29:05 +00:00
Tcp buffer bug fix (#79)
* start working on tracking down tcp buffer bug * mtu refactor * modularize test * more precise testing * tests fail, but is it the failure we are looking for? * fix typo in espradio link (#76) * implement a new backoff abstraction (#75) * rewrite backoff api * rewrite tcp.Conn.Write * keep fixing small things * much better Conn.Read implementation * fix critical overflow bug in internal.ConnRWBackoff --------- Co-authored-by: Joel Wetzell <jwetzell@yahoo.com>
This commit is contained in:
+9
-5
@@ -1,17 +1,21 @@
|
||||
package internal
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// ConnRWBackoff implements exponential backoff suitable for TCP connection
|
||||
// read/write polling. It starts at 1us and caps at 5ms, doubling on each consecutive backoff.
|
||||
func ConnRWBackoff(consecutiveBackoffs int) {
|
||||
const (
|
||||
minWait = time.Microsecond >> 1
|
||||
maxWait = 5 * time.Millisecond
|
||||
minWait = uint32(time.Microsecond) >> 1
|
||||
maxWait = 5 * uint32(time.Millisecond)
|
||||
maxShift = 23
|
||||
_overflowCheck = minWait << maxShift
|
||||
)
|
||||
wait := minWait << consecutiveBackoffs
|
||||
wait := minWait << min(consecutiveBackoffs, maxShift)
|
||||
if wait > maxWait {
|
||||
wait = maxWait
|
||||
}
|
||||
time.Sleep(wait)
|
||||
time.Sleep(time.Duration(wait))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user