summaryrefslogtreecommitdiffhomepage
path: root/conn
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-03-04 15:25:46 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-10 14:52:22 +0100
commitdbd949307e75bbd72d86e53aa57b74b20daab04d (patch)
tree2dac596a5125edc3a4149e37cd5a694b443c5a3c /conn
parentf26efb65f23acbd88785d1ae793fa3264c999673 (diff)
conn: inch BatchSize toward being non-dynamic
There's not really a use at the moment for making this configurable, and once bind_windows.go behaves like bind_std.go, we'll be able to use constants everywhere. So begin that simplification now. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'conn')
-rw-r--r--conn/bind_std.go18
-rw-r--r--conn/bind_windows.go2
-rw-r--r--conn/conn.go2
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