Skip to content

Commit 16d30c4

Browse files
Support AIX SO_REUSEADDR and SO_REUSEPORT (#1328)
* Update reuseport.go * Create reuseport_aix.go
1 parent bc24f9d commit 16d30c4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

reuseport/reuseport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build !windows && !aix
2+
// +build !windows,!aix
33

44
// Package reuseport provides TCP net.Listener with SO_REUSEPORT support.
55
//

reuseport/reuseport_aix.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package reuseport
2+
3+
import (
4+
"context"
5+
"net"
6+
"syscall"
7+
8+
"golang.org/x/sys/unix"
9+
)
10+
11+
var listenConfig = net.ListenConfig{
12+
Control: func(network, address string, c syscall.RawConn) (err error) {
13+
return c.Control(func(fd uintptr) {
14+
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
15+
if err == nil {
16+
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
17+
}
18+
})
19+
},
20+
}
21+
22+
// Listen returns TCP listener with SO_REUSEADDR and SO_REUSEPORT option set, so it uses
23+
func Listen(network, addr string) (net.Listener, error) {
24+
return listenConfig.Listen(context.Background(), network, addr)
25+
}

0 commit comments

Comments
 (0)