diff options
author | zhangyongding <54876819+zhangyongding@users.noreply.github.com> | 2022-06-26 16:08:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-26 10:08:47 +0200 |
commit | 16d30c474cea55710ff9a550f1b20b7b974053d9 (patch) | |
tree | c654633a428ffd7ce60d39a363c8c7c8571ce8be /reuseport | |
parent | Consolidate TCPKeepalive in server.Serve (#1320) (#1324) (diff) | |
download | fasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.tar.gz fasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.tar.bz2 fasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.zip |
* Update reuseport.go
* Create reuseport_aix.go
Diffstat (limited to 'reuseport')
-rw-r--r-- | reuseport/reuseport.go | 4 | ||||
-rw-r--r-- | reuseport/reuseport_aix.go | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/reuseport/reuseport.go b/reuseport/reuseport.go index 161f4e1..86ad397 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 0000000..bfac713 --- /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) +} |