Make listenConfig replaceable

This commit is contained in:
Viktor Liu
2025-07-16 00:20:06 +02:00
parent cc2acf4607
commit 1ba7f82a80
2 changed files with 14 additions and 4 deletions
+10 -4
View File
@@ -26,10 +26,9 @@ type controlFn func(network, address string, c syscall.RawConn) error
// that can apply socket options.
var controlFns = []controlFn{}
// listenConfig returns a net.ListenConfig that applies the controlFns to the
// socket prior to bind. This is used to apply socket buffer sizing and packet
// information OOB configuration for sticky sockets.
func listenConfig() *net.ListenConfig {
// listenConfigFn is a function that returns a net.ListenConfig.
// It can be replaced to use alternative network stacks.
var listenConfigFn = func() *net.ListenConfig {
return &net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
for _, fn := range controlFns {
@@ -41,3 +40,10 @@ func listenConfig() *net.ListenConfig {
},
}
}
// listenConfig returns a net.ListenConfig that applies the controlFns to the
// socket prior to bind. This is used to apply socket buffer sizing and packet
// information OOB configuration for sticky sockets.
func listenConfig() *net.ListenConfig {
return listenConfigFn()
}
+4
View File
@@ -13,6 +13,10 @@ var (
// export controlFns for Android to use
// is not thread safe and should only be modified during init.
ControlFns = &controlFns
// export listenConfigFn for external replacement
// is not thread safe and should only be modified during init.
ListenConfigFn = &listenConfigFn
)
type BatchReader = batchReader