implement a new backoff abstraction (#75)

This commit is contained in:
Pat Whittingslow
2026-04-14 16:11:03 -03:00
committed by GitHub
parent 191b8ee4cc
commit 5bde7a9979
5 changed files with 100 additions and 86 deletions
+9 -2
View File
@@ -53,6 +53,9 @@ type TCPPoolConfig struct {
ClosingTimeout time.Duration
// NewUserData is used to create user data used for each individual TCP connection and returned on GetTCP.
NewUserData func() any
// NewBackoff returns the backoff to use for every newly configured TCP connection.
// This should always return a static(non-method) function unless you know what you are doing.
NewBackoff func() lneto.BackoffStrategy
}
func NewTCPPool(cfg TCPPoolConfig) (*TCPPool, error) {
@@ -76,12 +79,16 @@ func NewTCPPool(cfg TCPPoolConfig) (*TCPPool, error) {
for i := range pool.conns {
bufoff := i * allocPerConn
txOff := bufoff + cfg.RxBufSize
err := pool.conns[i].Configure(tcp.ConnConfig{
conncfg := tcp.ConnConfig{
RxBuf: bufSpace[bufoff:txOff],
TxBuf: bufSpace[txOff : txOff+cfg.TxBufSize],
TxPacketQueueSize: cfg.QueueSize,
Logger: cfg.ConnLogger,
})
}
if cfg.NewBackoff != nil {
conncfg.RWBackoff = cfg.NewBackoff()
}
err := pool.conns[i].Configure(conncfg)
if err != nil {
return nil, err
}