reuseport_aix.go 633 B

12345678910111213141516171819202122232425
  1. package reuseport
  2. import (
  3. "context"
  4. "net"
  5. "syscall"
  6. "golang.org/x/sys/unix"
  7. )
  8. var listenConfig = net.ListenConfig{
  9. Control: func(network, address string, c syscall.RawConn) (err error) {
  10. return c.Control(func(fd uintptr) {
  11. err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
  12. if err == nil {
  13. err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
  14. }
  15. })
  16. },
  17. }
  18. // Listen returns a TCP listener with the SO_REUSEADDR and SO_REUSEPORT options set.
  19. func Listen(network, addr string) (net.Listener, error) {
  20. return listenConfig.Listen(context.Background(), network, addr)
  21. }