diff --git a/reuseport/reuseport.go b/reuseport/reuseport.go index 161f4e13c0..86ad397e32 100644 --- a/reuseport/reuseport.go +++ b/reuseport/reuseport.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build !windows && !aix +// +build !windows,!aix // Package reuseport provides TCP net.Listener with SO_REUSEPORT support. // diff --git a/reuseport/reuseport_aix.go b/reuseport/reuseport_aix.go new file mode 100644 index 0000000000..bfac71347d --- /dev/null +++ b/reuseport/reuseport_aix.go @@ -0,0 +1,25 @@ +package reuseport + +import ( + "context" + "net" + "syscall" + + "golang.org/x/sys/unix" +) + +var listenConfig = net.ListenConfig{ + Control: func(network, address string, c syscall.RawConn) (err error) { + return c.Control(func(fd uintptr) { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) + if err == nil { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) + } + }) + }, +} + +// Listen returns TCP listener with SO_REUSEADDR and SO_REUSEPORT option set, so it uses +func Listen(network, addr string) (net.Listener, error) { + return listenConfig.Listen(context.Background(), network, addr) +}