mirror of
https://github.com/libp2p/go-reuseport.git
synced 2025-09-26 19:01:11 +08:00
use SO_REUSEPORT_LB on FreeBSD (#106)
* feat: Add support for SO_REUSEPORT_LB option as per freeBSD * fix: address review comments * chore: updated to use build flags * chore: remove unnecessary code * chore: fix gofmt error
This commit is contained in:

committed by
GitHub

parent
0304740d59
commit
45f56813e4
27
control_freebsd.go
Normal file
27
control_freebsd.go
Normal file
@@ -0,0 +1,27 @@
|
||||
//go:build freebsd
|
||||
|
||||
package reuseport
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func Control(network, address string, c syscall.RawConn) (err error) {
|
||||
controlErr := c.Control(func(fd uintptr) {
|
||||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT_LB, 1)
|
||||
})
|
||||
if controlErr != nil {
|
||||
err = controlErr
|
||||
}
|
||||
return
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
//go:build !plan9 && !windows && !wasm
|
||||
//go:build !plan9 && !windows && !wasm && !freebsd
|
||||
|
||||
package reuseport
|
||||
|
||||
|
Reference in New Issue
Block a user