sing/common/control/reuse_linux.go
2022-06-30 17:39:41 +08:00

21 lines
498 B
Go

package control
import (
"syscall"
"github.com/sagernet/sing/common"
)
func ReuseAddr() Func {
return func(network, address string, conn syscall.RawConn) error {
var innerErr error
err := conn.Control(func(fd uintptr) {
const SO_REUSEPORT = 0xf
innerErr = common.AnyError(
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1),
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, SO_REUSEPORT, 1),
)
})
return common.AnyError(innerErr, err)
}
}