mirror of https://github.com/golang/go.git
Revert "net: remove fallback path in sysSocket"
This reverts CL 40364. Reason for revert: Fallback path is still required on Solaris. For #45964 For #59359 Change-Id: I4b8c8af77ee987cad6617221793b90c9a8829c3e Reviewed-on: https://go-review.googlesource.com/c/go/+/501276 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
ce8eadf591
commit
bd00528d04
|
|
@ -10,6 +10,7 @@
|
||||||
package net
|
package net
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"internal/poll"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
@ -18,8 +19,32 @@ import (
|
||||||
// descriptor as nonblocking and close-on-exec.
|
// descriptor as nonblocking and close-on-exec.
|
||||||
func sysSocket(family, sotype, proto int) (int, error) {
|
func sysSocket(family, sotype, proto int) (int, error) {
|
||||||
s, err := socketFunc(family, sotype|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, proto)
|
s, err := socketFunc(family, sotype|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, proto)
|
||||||
|
// On Linux the SOCK_NONBLOCK and SOCK_CLOEXEC flags were
|
||||||
|
// introduced in 2.6.27 kernel and on FreeBSD both flags were
|
||||||
|
// introduced in 10 kernel. If we get an EINVAL error on Linux
|
||||||
|
// or EPROTONOSUPPORT error on FreeBSD, fall back to using
|
||||||
|
// socket without them.
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return s, nil
|
||||||
|
default:
|
||||||
|
return -1, os.NewSyscallError("socket", err)
|
||||||
|
case syscall.EPROTONOSUPPORT, syscall.EINVAL:
|
||||||
|
}
|
||||||
|
|
||||||
|
// See ../syscall/exec_unix.go for description of ForkLock.
|
||||||
|
syscall.ForkLock.RLock()
|
||||||
|
s, err = socketFunc(family, sotype, proto)
|
||||||
|
if err == nil {
|
||||||
|
syscall.CloseOnExec(s)
|
||||||
|
}
|
||||||
|
syscall.ForkLock.RUnlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, os.NewSyscallError("socket", err)
|
return -1, os.NewSyscallError("socket", err)
|
||||||
}
|
}
|
||||||
|
if err = syscall.SetNonblock(s, true); err != nil {
|
||||||
|
poll.CloseFunc(s)
|
||||||
|
return -1, os.NewSyscallError("setnonblock", err)
|
||||||
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue