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
+4 -5
View File
@@ -48,6 +48,9 @@ type ConnConfig struct {
// Configure initializes the connection with the given buffer and queue configuration.
// Must be called before [Conn.Open]. Calling Configure on an active connection aborts it.
func (conn *Conn) Configure(cfg ConnConfig) error {
if cfg.RWBackoff == nil {
return lneto.ErrMissingHALConfig
}
conn.mu.Lock()
defer conn.mu.Unlock()
conn.abort()
@@ -302,11 +305,7 @@ func (conn *Conn) FreeInput() int {
}
func (conn *Conn) backoff(consecutiveBackoffs uint) {
if conn._backoff != nil {
conn._backoff.Do(consecutiveBackoffs)
} else {
internal.BackoffConnRW(consecutiveBackoffs)
}
conn._backoff.Do(consecutiveBackoffs)
}
func (conn *Conn) lockPipeConnID() (uint64, error) {
+7
View File
@@ -4,7 +4,9 @@ import (
"encoding/binary"
"net/netip"
"testing"
"time"
"github.com/soypat/lneto"
"github.com/soypat/lneto/internal"
)
@@ -26,6 +28,7 @@ func newTestConn(t *testing.T) *Conn {
TxBuf: make([]byte, 256),
RxQueueSize: 4,
TxQueueSize: 4,
RWBackoff: backoffYield,
})
if err != nil {
t.Fatal(err)
@@ -239,3 +242,7 @@ func TestConn_FrameOffset(t *testing.T) {
t.Fatalf("got %q, want %q", string(buf[:n]), "hi")
}
}
func backoffYield(backoffs uint) time.Duration {
return lneto.BackoffFlagGosched
}
+4 -6
View File
@@ -8,7 +8,6 @@ import (
"time"
"github.com/soypat/lneto"
"github.com/soypat/lneto/internal"
)
// lnetopacketconn is the lneto interpretation of
@@ -53,6 +52,9 @@ type PacketConnConfig struct {
// Configure initializes the PacketConn with the given buffer and queue configuration.
// Must be called before [PacketConn.Open]. Calling Configure on an active connection aborts it.
func (pc *PacketConn) Configure(cfg PacketConnConfig) error {
if cfg.RWBackoff == nil {
return lneto.ErrMissingHALConfig
}
pc.mu.Lock()
defer pc.mu.Unlock()
pc.abort()
@@ -243,11 +245,7 @@ func (pc *PacketConn) deadlineExceeded(deadline *time.Time) bool {
}
func (pc *PacketConn) backoff(n uint) {
if pc._backoff != nil {
pc._backoff.Do(n)
} else {
internal.BackoffConnRW(n)
}
pc._backoff.Do(n)
}
func (pc *PacketConn) lockConnID() (uint64, error) {