Files
libp2p/control_unix.go
Matt Joiner 28dc0654fa fix error handling when setting socket options (#102)
Both sockopt and control errors can't exist at the same time, but control errors should occur first, and so are given precedence.

Fixes #101
2023-04-25 05:20:04 -07:00

24 lines
465 B
Go

//go:build !plan9 && !windows && !wasm
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 controlErr != nil {
err = controlErr
}
return
}