mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-13 15:46:49 +03:00
Add reuseport support for Solaris (#2046)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !aix
|
||||
//go:build !windows && !aix && !solaris
|
||||
|
||||
// Package reuseport provides TCP net.Listener with SO_REUSEPORT support.
|
||||
//
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user