reuseport_solaris.go 684 B

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