mirror of https://github.com/golang/go.git
Revert "internal/poll: remove fallback path in accept"
This reverts CL 422375. Reason for revert: We still need the fallback path on Solaris. For #45964 For #59359 Change-Id: Ie598b9ef180708fb157080015aee44f67f6737c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/501275 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@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>
This commit is contained in:
parent
3d78c735fc
commit
7f26e9e5fb
|
|
@ -15,8 +15,36 @@ import "syscall"
|
||||||
// descriptor as nonblocking and close-on-exec.
|
// descriptor as nonblocking and close-on-exec.
|
||||||
func accept(s int) (int, syscall.Sockaddr, string, error) {
|
func accept(s int) (int, syscall.Sockaddr, string, error) {
|
||||||
ns, sa, err := Accept4Func(s, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC)
|
ns, sa, err := Accept4Func(s, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC)
|
||||||
if err != nil {
|
// On Linux the accept4 system call was introduced in 2.6.28
|
||||||
|
// kernel and on FreeBSD it was introduced in 10 kernel. If we
|
||||||
|
// get an ENOSYS error on both Linux and FreeBSD, or EINVAL
|
||||||
|
// error on Linux, fall back to using accept.
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return ns, sa, "", nil
|
||||||
|
default: // errors other than the ones listed
|
||||||
return -1, sa, "accept4", err
|
return -1, sa, "accept4", err
|
||||||
|
case syscall.ENOSYS: // syscall missing
|
||||||
|
case syscall.EINVAL: // some Linux use this instead of ENOSYS
|
||||||
|
case syscall.EACCES: // some Linux use this instead of ENOSYS
|
||||||
|
case syscall.EFAULT: // some Linux use this instead of ENOSYS
|
||||||
|
}
|
||||||
|
|
||||||
|
// See ../syscall/exec_unix.go for description of ForkLock.
|
||||||
|
// It is probably okay to hold the lock across syscall.Accept
|
||||||
|
// because we have put fd.sysfd into non-blocking mode.
|
||||||
|
// However, a call to the File method will put it back into
|
||||||
|
// blocking mode. We can't take that risk, so no use of ForkLock here.
|
||||||
|
ns, sa, err = AcceptFunc(s)
|
||||||
|
if err == nil {
|
||||||
|
syscall.CloseOnExec(ns)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return -1, nil, "accept", err
|
||||||
|
}
|
||||||
|
if err = syscall.SetNonblock(ns, true); err != nil {
|
||||||
|
CloseFunc(ns)
|
||||||
|
return -1, nil, "setnonblock", err
|
||||||
}
|
}
|
||||||
return ns, sa, "", nil
|
return ns, sa, "", nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue