aboutsummaryrefslogtreecommitdiff
path: root/reuseport/reuseport_aix.go
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/reuseport_aix.go
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/reuseport_aix.go')
-rw-r--r--reuseport/reuseport_aix.go25
1 files changed, 25 insertions, 0 deletions
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)
+}