1
0
mirror of https://github.com/golang/go synced 2024-11-25 09:57:57 -07:00

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
This commit is contained in:
Mikio Hara 2013-03-30 15:21:22 +09:00
parent 5851b974a3
commit 4b7bf73c4b

View File

@ -25,7 +25,8 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
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
// address with reusable UDP port when the given ulsa
// 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,
closesocket(s)
return nil, err
}
}
if ulsa != nil {
if err = syscall.Bind(s, ulsa); err != nil {
closesocket(s)
return nil, err
@ -48,6 +52,7 @@ func socket(net string, f, t, p int, ipv6only bool, ulsa, ursa syscall.Sockaddr,
return nil, err
}
// This socket is used by a dialer.
if ursa != nil {
if !deadline.IsZero() {
setWriteDeadline(fd, deadline)