diff options
Diffstat (limited to 'conn')
-rw-r--r-- | conn/bind_std.go | 18 | ||||
-rw-r--r-- | conn/bind_windows.go | 2 | ||||
-rw-r--r-- | conn/conn.go | 2 |
3 files changed, 9 insertions, 13 deletions
diff --git a/conn/bind_std.go b/conn/bind_std.go index a164f56..b9da4c3 100644 --- a/conn/bind_std.go +++ b/conn/bind_std.go @@ -31,21 +31,13 @@ type StdNetBind struct { blackhole6 bool ipv4PC *ipv4.PacketConn ipv6PC *ipv6.PacketConn - batchSize int udpAddrPool sync.Pool ipv4MsgsPool sync.Pool ipv6MsgsPool sync.Pool } -func NewStdNetBind() Bind { return NewStdNetBindBatch(DefaultBatchSize) } - -func NewStdNetBindBatch(maxBatchSize int) Bind { - if maxBatchSize == 0 { - maxBatchSize = DefaultBatchSize - } +func NewStdNetBind() Bind { return &StdNetBind{ - batchSize: maxBatchSize, - udpAddrPool: sync.Pool{ New: func() any { return &net.UDPAddr{ @@ -56,7 +48,7 @@ func NewStdNetBindBatch(maxBatchSize int) Bind { ipv4MsgsPool: sync.Pool{ New: func() any { - msgs := make([]ipv4.Message, maxBatchSize) + msgs := make([]ipv4.Message, IdealBatchSize) for i := range msgs { msgs[i].Buffers = make(net.Buffers, 1) msgs[i].OOB = make([]byte, srcControlSize) @@ -67,7 +59,7 @@ func NewStdNetBindBatch(maxBatchSize int) Bind { ipv6MsgsPool: sync.Pool{ New: func() any { - msgs := make([]ipv6.Message, maxBatchSize) + msgs := make([]ipv6.Message, IdealBatchSize) for i := range msgs { msgs[i].Buffers = make(net.Buffers, 1) msgs[i].OOB = make([]byte, srcControlSize) @@ -240,8 +232,10 @@ func (s *StdNetBind) receiveIPv6(buffs [][]byte, sizes []int, eps []Endpoint) (n return numMsgs, nil } +// TODO: When all Binds handle IdealBatchSize, remove this dynamic function and +// rename the IdealBatchSize constant to BatchSize. func (s *StdNetBind) BatchSize() int { - return s.batchSize + return IdealBatchSize } func (s *StdNetBind) Close() error { diff --git a/conn/bind_windows.go b/conn/bind_windows.go index 5a0b8c2..e44cc7b 100644 --- a/conn/bind_windows.go +++ b/conn/bind_windows.go @@ -321,6 +321,8 @@ func (bind *WinRingBind) Close() error { return nil } +// TODO: When all Binds handle IdealBatchSize, remove this dynamic function and +// rename the IdealBatchSize constant to BatchSize. func (bind *WinRingBind) BatchSize() int { // TODO: implement batching in and out of the ring return 1 diff --git a/conn/conn.go b/conn/conn.go index 9cbd0af..a9c70b5 100644 --- a/conn/conn.go +++ b/conn/conn.go @@ -16,7 +16,7 @@ import ( ) const ( - DefaultBatchSize = 128 // maximum number of packets handled per read and write + IdealBatchSize = 128 // maximum number of packets handled per read and write ) // A ReceiveFunc receives at least one packet from the network and writes them |