mirror of
https://github.com/soypat/lneto.git
synced 2026-08-20 14:39:02 +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:
+4
-5
@@ -62,6 +62,9 @@ type ConnConfig struct {
|
||||
}
|
||||
|
||||
func (conn *Conn) Configure(config ConnConfig) (err error) {
|
||||
if config.RWBackoff == nil {
|
||||
return lneto.ErrMissingHALConfig
|
||||
}
|
||||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
err = conn.h.SetBuffers(config.TxBuf, config.RxBuf, config.TxPacketQueueSize)
|
||||
@@ -483,9 +486,5 @@ func (conn *Conn) ConnectionID() *uint64 {
|
||||
}
|
||||
|
||||
func (conn *Conn) backoff(consecutiveBackoffs uint) {
|
||||
if conn._backoff != nil {
|
||||
conn._backoff.Do(consecutiveBackoffs)
|
||||
} else {
|
||||
internal.BackoffConnRW(consecutiveBackoffs)
|
||||
}
|
||||
conn._backoff.Do(consecutiveBackoffs)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"net/netip"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
)
|
||||
|
||||
func newConfiguredConn(t *testing.T) *Conn {
|
||||
@@ -14,6 +16,7 @@ func newConfiguredConn(t *testing.T) *Conn {
|
||||
RxBuf: make([]byte, 512),
|
||||
TxBuf: make([]byte, 512),
|
||||
TxPacketQueueSize: 4,
|
||||
RWBackoff: backoffYield,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -121,6 +124,7 @@ func TestConn_Configure_Twice(t *testing.T) {
|
||||
RxBuf: make([]byte, 1024),
|
||||
TxBuf: make([]byte, 1024),
|
||||
TxPacketQueueSize: 8,
|
||||
RWBackoff: backoffYield,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("reconfigure should succeed: %v", err)
|
||||
@@ -160,3 +164,7 @@ func TestConn_ImplementsNetConn(t *testing.T) {
|
||||
} = conn
|
||||
_ = net.ErrClosed
|
||||
}
|
||||
|
||||
func backoffYield(consecutiveBackoffs uint) time.Duration {
|
||||
return lneto.BackoffFlagGosched
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user