mirror of
https://github.com/netbirdio/wireguard-go.git
synced 2026-05-22 17:08:51 -07:00
Make listenConfig replaceable
This commit is contained in:
+10
-4
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user