diff --git a/conn/controlfns.go b/conn/controlfns.go index 4f7d90f..c658cea 100644 --- a/conn/controlfns.go +++ b/conn/controlfns.go @@ -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() +} diff --git a/conn/export.go b/conn/export.go index 9c905cb..e1dc88a 100644 --- a/conn/export.go +++ b/conn/export.go @@ -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