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