diff options
Diffstat (limited to 'libgo/go/net/sockopt_bsd.go')
-rw-r--r-- | libgo/go/net/sockopt_bsd.go | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/libgo/go/net/sockopt_bsd.go b/libgo/go/net/sockopt_bsd.go index bc764650627..af88814b4b9 100644 --- a/libgo/go/net/sockopt_bsd.go +++ b/libgo/go/net/sockopt_bsd.go @@ -13,38 +13,32 @@ import ( "syscall" ) -func setDefaultSockopts(s, f, t int) error { +func setDefaultSockopts(s, f, t int, ipv6only bool) error { switch f { case syscall.AF_INET6: - // Allow both IP versions even if the OS default is otherwise. - // Note that some operating systems never admit this option. - syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0) - } - - if f == syscall.AF_UNIX || - (f == syscall.AF_INET || f == syscall.AF_INET6) && t == syscall.SOCK_STREAM { - // Allow reuse of recently-used addresses. - err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) - if err != nil { - return os.NewSyscallError("setsockopt", err) - } - - // Allow reuse of recently-used ports. - // This option is supported only in descendants of 4.4BSD, - // to make an effective multicast application and an application - // that requires quick draw possible. - err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) - if err != nil { - return os.NewSyscallError("setsockopt", err) + if ipv6only { + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 1) + } else { + // Allow both IP versions even if the OS default + // is otherwise. Note that some operating systems + // never admit this option. + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0) } } - // Allow broadcast. err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1) if err != nil { return os.NewSyscallError("setsockopt", err) } + return nil +} +func setDefaultListenerSockopts(s int) error { + // Allow reuse of recently-used addresses. + err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) + if err != nil { + return os.NewSyscallError("setsockopt", err) + } return nil } @@ -55,9 +49,15 @@ func setDefaultMulticastSockopts(s int) error { if err != nil { return os.NewSyscallError("setsockopt", err) } - err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) - if err != nil { - return os.NewSyscallError("setsockopt", err) + // Allow reuse of recently-used ports. + // This option is supported only in descendants of 4.4BSD, + // to make an effective multicast application that requires + // quick draw possible. + if syscall.SO_REUSEPORT != 0 { + err = syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) + if err != nil { + return os.NewSyscallError("setsockopt", err) + } } return nil } |