2024-01-19 00:24:54 +05:30
|
|
|
//go:build !plan9 && !windows && !wasm
|
2019-06-09 09:24:20 +02:00
|
|
|
|
|
|
|
package reuseport
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2023-06-30 09:41:32 -04:00
|
|
|
func Control(network, address string, c syscall.RawConn) (err error) {
|
|
|
|
controlErr := c.Control(func(fd uintptr) {
|
2019-06-09 09:24:20 +02:00
|
|
|
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)
|
|
|
|
})
|
2023-06-30 09:41:32 -04:00
|
|
|
if controlErr != nil {
|
|
|
|
err = controlErr
|
|
|
|
}
|
|
|
|
return
|
2019-06-09 09:24:20 +02:00
|
|
|
}
|