mirror of
https://github.com/golang/go.git
synced 2025-11-11 06:01:06 +00:00
net: use F_DUPFD_CLOEXEC when duping fds
This means that in the common case (modern kernel), we only make 1 system call to dup instead of two, and we also avoid grabbing the syscall.ForkLock. R=golang-dev, iant CC=golang-dev https://golang.org/cl/12476043
This commit is contained in:
parent
f7910128e7
commit
37feacf623
4 changed files with 42 additions and 9 deletions
|
|
@ -12,14 +12,11 @@ import (
|
|||
)
|
||||
|
||||
func newFileFD(f *os.File) (*netFD, error) {
|
||||
syscall.ForkLock.RLock()
|
||||
fd, err := syscall.Dup(int(f.Fd()))
|
||||
fd, err := dupCloseOnExec(int(f.Fd()))
|
||||
if err != nil {
|
||||
syscall.ForkLock.RUnlock()
|
||||
return nil, os.NewSyscallError("dup", err)
|
||||
}
|
||||
syscall.CloseOnExec(fd)
|
||||
syscall.ForkLock.RUnlock()
|
||||
|
||||
if err = syscall.SetNonblock(fd, true); err != nil {
|
||||
closesocket(fd)
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue