Commit 4b7bf73c authored by Mikio Hara's avatar Mikio Hara

net: avoid use of listener socket options on active open sockets

This CL ensures we use the correct socket options for
passive and active open sockets.

For the passive open sockets created by Listen functions,
additional SO_REUSEADDR, SO_REUSEPORT options are required
for the quick service restart and/or multicasting.

For the active open sockets created by Dial functions, no
additional options are required.

R=golang-dev, dave, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/7795050
parent 5851b974
...@@ -25,7 +25,8 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, ...@@ -25,7 +25,8 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
return nil, err return nil, err
} }
if ulsa != nil { // This socket is used by a listener.
if ulsa != nil && ursa == nil {
// We provide a socket that listens to a wildcard // We provide a socket that listens to a wildcard
// address with reusable UDP port when the given ulsa // address with reusable UDP port when the given ulsa
// is an appropriate UDP multicast address prefix. // is an appropriate UDP multicast address prefix.
...@@ -37,6 +38,9 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, ...@@ -37,6 +38,9 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
closesocket(s) closesocket(s)
return nil, err return nil, err
} }
}
if ulsa != nil {
if err = syscall.Bind(s, ulsa); err != nil { if err = syscall.Bind(s, ulsa); err != nil {
closesocket(s) closesocket(s)
return nil, err return nil, err
...@@ -48,6 +52,7 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr, ...@@ -48,6 +52,7 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
return nil, err return nil, err
} }
// This socket is used by a dialer.
if ursa != nil { if ursa != nil {
if !deadline.IsZero() { if !deadline.IsZero() {
setWriteDeadline(fd, deadline) setWriteDeadline(fd, deadline)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment