aboutsummaryrefslogtreecommitdiff
path: root/reuseport
diff options
context:
space:
mode:
authorGravatar zhangyongding <54876819+zhangyongding@users.noreply.github.com> 2022-06-26 16:08:47 +0800
committerGravatar GitHub <noreply@github.com> 2022-06-26 10:08:47 +0200
commit16d30c474cea55710ff9a550f1b20b7b974053d9 (patch)
treec654633a428ffd7ce60d39a363c8c7c8571ce8be /reuseport
parentConsolidate TCPKeepalive in server.Serve (#1320) (#1324) (diff)
downloadfasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.tar.gz
fasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.tar.bz2
fasthttp-16d30c474cea55710ff9a550f1b20b7b974053d9.zip
Support AIX SO_REUSEADDR and SO_REUSEPORT (#1328)v1.38.0
* Update reuseport.go * Create reuseport_aix.go
Diffstat (limited to 'reuseport')
-rw-r--r--reuseport/reuseport.go4
-rw-r--r--reuseport/reuseport_aix.go25
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)
+}