diff --git a/uri.go b/uri.go index ec4cf88f..d4ac5817 100644 --- a/uri.go +++ b/uri.go @@ -7,7 +7,6 @@ import ( "os" "strconv" "strings" - "syscall" "github.com/l7mp/stunner/internal/util" stnrv1 "github.com/l7mp/stunner/pkg/apis/v1" @@ -166,10 +165,3 @@ func getStunnerProtoForURI(u *url.URL) (string, error) { return "", fmt.Errorf("Invalid scheme/protocol in URI %q", u.String()) } - -func reuseAddr(network, address string, conn syscall.RawConn) error { - return conn.Control(func(descriptor uintptr) { - _ = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) - // syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) - }) -} diff --git a/uri_unix.go b/uri_unix.go new file mode 100644 index 00000000..fa545c48 --- /dev/null +++ b/uri_unix.go @@ -0,0 +1,12 @@ +//go:build unix + +package stunner + +import "syscall" + +func reuseAddr(network, address string, conn syscall.RawConn) error { + return conn.Control(func(descriptor uintptr) { + _ = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + // syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + }) +} diff --git a/uri_windows.go b/uri_windows.go new file mode 100644 index 00000000..eedc298c --- /dev/null +++ b/uri_windows.go @@ -0,0 +1,12 @@ +//go:build windows + +package stunner + +import "syscall" + +func reuseAddr(network, address string, conn syscall.RawConn) error { + return conn.Control(func(descriptor uintptr) { + _ = syscall.SetsockoptInt(syscall.Handle(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + // syscall.SetsockoptInt(syscall.Handle(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + }) +}