1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:44:44 -07:00

net, internal/poll, net/internal/socktest: set SOCK_{CLOEXEC,NONBLOCK} atomically on NetBSD

NetBSD supports the SOCK_CLOEXEC and SOCK_NONBLOCK flags to the socket
syscall since version 6.0. The same version also introduced the paccept
syscall which can be used to implement syscall.Accept4.

Follows CL 40895

Change-Id: I9e4e1829b0382744c7799f4e58929a53b4e193f7
Reviewed-on: https://go-review.googlesource.com/94295
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tobias Klauser 2018-02-15 12:20:27 +01:00 committed by Tobias Klauser
parent 33eb0633e1
commit 9542ba674d
15 changed files with 75 additions and 7 deletions

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build dragonfly freebsd linux // +build dragonfly freebsd linux netbsd
package poll package poll

View File

@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that // This file implements sysSocket and accept for platforms that
// provide a fast path for setting SetNonblock and CloseOnExec. // provide a fast path for setting SetNonblock and CloseOnExec.
// +build dragonfly freebsd linux // +build dragonfly freebsd linux netbsd
package poll package poll

View File

@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that do not // This file implements sysSocket and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec. // provide a fast path for setting SetNonblock and CloseOnExec.
// +build darwin nacl netbsd openbsd solaris // +build darwin nacl openbsd solaris
package poll package poll

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build dragonfly freebsd linux // +build dragonfly freebsd linux netbsd
package socktest package socktest

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build dragonfly freebsd linux // +build dragonfly freebsd linux netbsd
package net package net

View File

@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that // This file implements sysSocket and accept for platforms that
// provide a fast path for setting SetNonblock and CloseOnExec. // provide a fast path for setting SetNonblock and CloseOnExec.
// +build dragonfly freebsd linux // +build dragonfly freebsd linux netbsd
package net package net

View File

@ -5,7 +5,7 @@
// This file implements sysSocket and accept for platforms that do not // This file implements sysSocket and accept for platforms that do not
// provide a fast path for setting SetNonblock and CloseOnExec. // provide a fast path for setting SetNonblock and CloseOnExec.
// +build darwin nacl netbsd openbsd solaris // +build darwin nacl openbsd solaris
package net package net

View File

@ -118,6 +118,25 @@ func Pipe2(p []int, flags int) error {
return err return err
} }
//sys paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error)
func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
var rsa RawSockaddrAny
var len _Socklen = SizeofSockaddrAny
nfd, err = paccept(fd, &rsa, &len, nil, flags)
if err != nil {
return
}
if len > SizeofSockaddrAny {
panic("RawSockaddrAny too small")
}
sa, err = anyToSockaddr(&rsa)
if err != nil {
Close(nfd)
nfd = 0
}
return
}
//sys getdents(fd int, buf []byte) (n int, err error) //sys getdents(fd int, buf []byte) (n int, err error)
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) { func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
return getdents(fd, buf) return getdents(fd, buf)

View File

@ -242,3 +242,7 @@ type Termios C.struct_termios
// Sysctl // Sysctl
type Sysctlnode C.struct_sysctlnode type Sysctlnode C.struct_sysctlnode
// Signals
type sigset C.sigset_t

View File

@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func getdents(fd int, buf []byte) (n int, err error) { func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer var _p0 unsafe.Pointer
if len(buf) > 0 { if len(buf) > 0 {

View File

@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func getdents(fd int, buf []byte) (n int, err error) { func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer var _p0 unsafe.Pointer
if len(buf) > 0 { if len(buf) > 0 {

View File

@ -271,6 +271,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func paccept(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, sigmask *sigset, flags int) (nfd int, err error) {
r0, _, e1 := Syscall6(SYS_PACCEPT, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(unsafe.Pointer(sigmask)), uintptr(flags), 0)
nfd = int(r0)
if e1 != 0 {
err = errnoErr(e1)
}
return
}
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
func getdents(fd int, buf []byte) (n int, err error) { func getdents(fd int, buf []byte) (n int, err error) {
var _p0 unsafe.Pointer var _p0 unsafe.Pointer
if len(buf) > 0 { if len(buf) > 0 {

View File

@ -402,3 +402,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte X_sysctl_parent [8]byte
X_sysctl_desc [8]byte X_sysctl_desc [8]byte
} }
type sigset struct {
X__bits [4]uint32
}

View File

@ -409,3 +409,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte X_sysctl_parent [8]byte
X_sysctl_desc [8]byte X_sysctl_desc [8]byte
} }
type sigset struct {
X__bits [4]uint32
}

View File

@ -407,3 +407,7 @@ type Sysctlnode struct {
X_sysctl_parent [8]byte X_sysctl_parent [8]byte
X_sysctl_desc [8]byte X_sysctl_desc [8]byte
} }
type sigset struct {
X__bits [4]uint32
}