Skip to content

Commit

Permalink
Support AIX SO_REUSEADDR and SO_REUSEPORT (#1328)
Browse files Browse the repository at this point in the history
* Update reuseport.go

* Create reuseport_aix.go
  • Loading branch information
zhangyongding committed Jun 26, 2022
1 parent bc24f9d commit 16d30c4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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.
//
Expand Down
25 changes: 25 additions & 0 deletions 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)
}

0 comments on commit 16d30c4

Please sign in to comment.