diff options
author | Wolfy-J <[email protected]> | 2019-12-23 15:41:23 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-12-23 15:41:23 +0300 |
commit | 7811cf537555f3fa39369e112e286477c26622e1 (patch) | |
tree | 2b8fcdd2370baea193617ed45328d34ec1072772 /util/network.go | |
parent | 74002b52ef690310c2da96521a7e23f5a653ae96 (diff) |
- enable port reuse on *unix
Diffstat (limited to 'util/network.go')
-rw-r--r-- | util/network.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/util/network.go b/util/network.go index b9066de7..f8f8fb36 100644 --- a/util/network.go +++ b/util/network.go @@ -1,3 +1,5 @@ +// +build !windows + package util import ( @@ -27,7 +29,15 @@ func CreateListener(address string) (net.Listener, error) { } } - return net.Listen(dsn[0], dsn[1]) + ls := net.ListenConfig{ + Control: func(network, address string, c syscall.RawConn) error { + return c.Control(func(descriptor uintptr) { + syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + }) + }, + } + + return ls.Listen(dsn[0], dsn[1]) } // fileExists checks if a file exists and is not a directory before we |