-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add platform-specific socket setting functions (#14)
* Add platform-specific socket setting functions The commit introduces two new files called `util_windows.go` and `util_unix.go` which contain specific socket options' settings for Windows and Unix. These functions replace the previous implementation in `util.go`, resulting in cleaner code and segregating functionalities based on the system platform. * Replace SO_REUSEADDR with SO_REUSEPORT in Unix socket settings The commit updates the Unix socket settings function from using the SO_REUSEADDR option to the SO_REUSEPORT option. This change is made in the `util_unix.go` file. SO_REUSEPORT is preferable as it permits multiple sockets to be bound to an identical socket address.
- Loading branch information
1 parent
dab4855
commit 2f68937
Showing
3 changed files
with
36 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |