Add reuseport support for Solaris (#2046)

This commit is contained in:
jwntree
2025-08-04 23:27:16 +09:00
committed by GitHub
parent 01d533ad15
commit 1d8fe19359
2 changed files with 32 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build !windows && !aix
//go:build !windows && !aix && !solaris
// Package reuseport provides TCP net.Listener with SO_REUSEPORT support.
//
+31
View File
@@ -0,0 +1,31 @@
//go:build solaris
package reuseport
import (
"context"
"net"
"syscall"
"golang.org/x/sys/unix"
)
const (
_SO_REUSEPORT = 0x100e
)
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, _SO_REUSEPORT, 1)
}
})
},
}
// Listen returns a TCP listener with the SO_REUSEADDR and SO_REUSEPORT options set.
func Listen(network, addr string) (net.Listener, error) {
return listenConfig.Listen(context.Background(), network, addr)
}