mirror of
https://github.com/soypat/lneto.git
synced 2026-08-17 05:13:27 +00:00
implement a new backoff abstraction (#75)
This commit is contained in:
+9
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user