diff --git a/util.go b/util.go index 6be3e20..d673754 100644 --- a/util.go +++ b/util.go @@ -19,7 +19,6 @@ import ( "github.com/pion/sdp/v3" "github.com/pion/turn/v2" "github.com/pion/webrtc/v3" - "golang.org/x/sys/unix" "golang.org/x/text/language" "golang.org/x/text/message" ) @@ -362,14 +361,7 @@ func StartTurnServer(ctx context.Context, publicIP string) *turn.Server { // will load-balance received packets per the IP 5-tuple listenerConfig := &net.ListenConfig{ Control: func(network, address string, conn syscall.RawConn) error { - var operr error - if err = conn.Control(func(fd uintptr) { - operr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) - }); err != nil { - return err - } - - return operr + return setSocketOptions(network, address, conn) }, } diff --git a/util_unix.go b/util_unix.go new file mode 100644 index 0000000..3de67b6 --- /dev/null +++ b/util_unix.go @@ -0,0 +1,19 @@ +//go:build unix + +package sfu + +import ( + "golang.org/x/sys/unix" + "syscall" +) + +func setSocketOptions(network, address string, conn syscall.RawConn) error { + var operr error + if err := conn.Control(func(fd uintptr) { + operr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) + }); err != nil { + return err + } + + return operr +} diff --git a/util_windows.go b/util_windows.go new file mode 100644 index 0000000..c411859 --- /dev/null +++ b/util_windows.go @@ -0,0 +1,16 @@ +//go:build windows + +package sfu + +import "syscall" + +func setSocketOptions(network, address string, conn syscall.RawConn) error { + var operr error + if err := conn.Control(func(fd uintptr) { + operr = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + }); err != nil { + return err + } + + return operr +}