Fix: set SO_REUSEADDR for UDP listeners on linux (#630)

This commit is contained in:
duama
2020-04-11 21:45:56 +08:00
committed by GitHub
parent 3ccd7def86
commit 2750c7ead0
5 changed files with 48 additions and 1 deletions

View File

@ -31,7 +31,11 @@ func setsockopt(c *net.UDPConn, addr string) error {
}
rc.Control(func(fd uintptr) {
err = syscall.SetsockoptInt(int(fd), syscall.SOL_IP, syscall.IP_TRANSPARENT, 1)
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
if err == nil {
err = syscall.SetsockoptInt(int(fd), syscall.SOL_IP, syscall.IP_TRANSPARENT, 1)
}
if err == nil && isIPv6 {
err = syscall.SetsockoptInt(int(fd), syscall.SOL_IPV6, IPV6_TRANSPARENT, 1)
}