mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net, internal/poll, net/internal/socktest: use SOCK_{CLOEXEC,NONBLOCK} accept4/socket flags on OpenBSD
The SOCK_CLOEXEC and SOCK_NONBLOCK flags to the socket syscall and the accept4 syscall are supported since OpenBSD 5.7. Follows CL 40895 and CL 94295 Change-Id: Icaf35ace2ef5e73279a70d4f1a9fbf3be9371e6c Reviewed-on: https://go-review.googlesource.com/97196 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
db7af2e67b
commit
144bf04a2b
15 changed files with 65 additions and 7 deletions
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build dragonfly freebsd linux netbsd
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package poll
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// This file implements sysSocket and accept for platforms that
|
||||
// provide a fast path for setting SetNonblock and CloseOnExec.
|
||||
|
||||
// +build dragonfly freebsd linux netbsd
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package poll
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// This file implements sysSocket and accept for platforms that do not
|
||||
// provide a fast path for setting SetNonblock and CloseOnExec.
|
||||
|
||||
// +build darwin nacl openbsd solaris
|
||||
// +build darwin nacl solaris
|
||||
|
||||
package poll
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build dragonfly freebsd linux netbsd
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package socktest
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build dragonfly freebsd linux netbsd
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package net
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// This file implements sysSocket and accept for platforms that
|
||||
// provide a fast path for setting SetNonblock and CloseOnExec.
|
||||
|
||||
// +build dragonfly freebsd linux netbsd
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package net
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// This file implements sysSocket and accept for platforms that do not
|
||||
// provide a fast path for setting SetNonblock and CloseOnExec.
|
||||
|
||||
// +build darwin nacl openbsd solaris
|
||||
// +build darwin nacl solaris
|
||||
|
||||
package net
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,25 @@ func Pipe(p []int) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
//sys accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, 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 = accept4(fd, &rsa, &len, 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)
|
||||
func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
|
||||
return getdents(fd, buf)
|
||||
|
|
|
|||
|
|
@ -1177,7 +1177,9 @@ const (
|
|||
SIOCSSPPPPARAMS = 0x80206993
|
||||
SIOCSVH = 0xc02069f5
|
||||
SIOCSVNETID = 0x802069a6
|
||||
SOCK_CLOEXEC = 0x8000
|
||||
SOCK_DGRAM = 0x2
|
||||
SOCK_NONBLOCK = 0x4000
|
||||
SOCK_RAW = 0x3
|
||||
SOCK_RDM = 0x4
|
||||
SOCK_SEQPACKET = 0x5
|
||||
|
|
|
|||
|
|
@ -1176,7 +1176,9 @@ const (
|
|||
SIOCSSPPPPARAMS = 0x80206993
|
||||
SIOCSVH = 0xc02069f5
|
||||
SIOCSVNETID = 0x802069a6
|
||||
SOCK_CLOEXEC = 0x8000
|
||||
SOCK_DGRAM = 0x2
|
||||
SOCK_NONBLOCK = 0x4000
|
||||
SOCK_RAW = 0x3
|
||||
SOCK_RDM = 0x4
|
||||
SOCK_SEQPACKET = 0x5
|
||||
|
|
|
|||
|
|
@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
|
|||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
|
||||
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(buf) > 0 {
|
||||
|
|
|
|||
|
|
@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
|
|||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
|
||||
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(buf) > 0 {
|
||||
|
|
|
|||
|
|
@ -271,6 +271,17 @@ func pipe(p *[2]_C_int) (err error) {
|
|||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func accept4(fd int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (nfd int, err error) {
|
||||
r0, _, e1 := Syscall6(SYS_ACCEPT4, uintptr(fd), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 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) {
|
||||
var _p0 unsafe.Pointer
|
||||
if len(buf) > 0 {
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ const (
|
|||
SYS_DUP2 = 90 // { int sys_dup2(int from, int to); }
|
||||
SYS_NANOSLEEP = 91 // { int sys_nanosleep(const struct timespec *rqtp, \
|
||||
SYS_FCNTL = 92 // { int sys_fcntl(int fd, int cmd, ... void *arg); }
|
||||
SYS_ACCEPT4 = 93 // { int sys_accept4(int s, struct sockaddr *name, \
|
||||
SYS___THRSLEEP = 94 // { int sys___thrsleep(const volatile void *ident, \
|
||||
SYS_FSYNC = 95 // { int sys_fsync(int fd); }
|
||||
SYS_SETPRIORITY = 96 // { int sys_setpriority(int which, id_t who, int prio); }
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ const (
|
|||
SYS_DUP2 = 90 // { int sys_dup2(int from, int to); }
|
||||
SYS_NANOSLEEP = 91 // { int sys_nanosleep(const struct timespec *rqtp, \
|
||||
SYS_FCNTL = 92 // { int sys_fcntl(int fd, int cmd, ... void *arg); }
|
||||
SYS_ACCEPT4 = 93 // { int sys_accept4(int s, struct sockaddr *name, \
|
||||
SYS___THRSLEEP = 94 // { int sys___thrsleep(const volatile void *ident, \
|
||||
SYS_FSYNC = 95 // { int sys_fsync(int fd); }
|
||||
SYS_SETPRIORITY = 96 // { int sys_setpriority(int which, id_t who, int prio); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue