Skip to content

Commit

Permalink
feat: Add support for SO_REUSEPORT_LB option as per freeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyaprem committed Aug 4, 2023
1 parent 35f7416 commit e965df1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions control_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ import (
"golang.org/x/sys/unix"
)

// This value has been taken from https://reviews.freebsd.org/D11003 since this is not yet provided in golang.
const FREEBSD_SO_REUSEPORT_LB = 0x00010000

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, FREEBSD_SO_REUSEPORT_LB, 1)
})
if controlErr != nil {
err = controlErr
Expand Down

0 comments on commit e965df1

Please sign in to comment.