Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add platform-specific socket setting functions #14

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
},
}

Expand Down
19 changes: 19 additions & 0 deletions util_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions util_windows.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading