mirror of
https://github.com/golang/go
synced 2024-11-24 04:40:24 -07:00
internal/poll, net, syscall: use accept4 on solaris
Solaris supports accept4 since version 11.4, see https://docs.oracle.com/cd/E88353_01/html/E37843/accept4-3c.html Use it in internal/poll.accept like on other platforms. Change-Id: I3d9830a85e93bbbed60486247c2f91abc646371f Reviewed-on: https://go-review.googlesource.com/c/go/+/403394 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Benny Siegert <bsiegert@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
0537a74b76
commit
3e00bd0ae4
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
|
||||
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
|
||||
package poll
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// This file implements accept for platforms that provide a fast path for
|
||||
// setting SetNonblock and CloseOnExec.
|
||||
|
||||
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
|
||||
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
|
||||
package poll
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// This file implements accept for platforms that do not provide a fast path for
|
||||
// setting SetNonblock and CloseOnExec.
|
||||
|
||||
//go:build aix || darwin || (js && wasm) || (solaris && !illumos)
|
||||
//go:build aix || darwin || (js && wasm)
|
||||
|
||||
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.
|
||||
|
||||
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
|
||||
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
|
||||
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.
|
||||
|
||||
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
|
||||
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
|
||||
package net
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// This file implements sysSocket for platforms that provide a fast path for
|
||||
// setting SetNonblock and CloseOnExec.
|
||||
|
||||
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
|
||||
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||||
|
||||
package net
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
// This file implements sysSocket for platforms that do not provide a fast path
|
||||
// for setting SetNonblock and CloseOnExec.
|
||||
|
||||
//go:build aix || darwin || (solaris && !illumos)
|
||||
//go:build aix || darwin
|
||||
|
||||
package net
|
||||
|
||||
|
@ -21,7 +21,7 @@ package cgo
|
||||
#cgo openbsd LDFLAGS: -lpthread
|
||||
#cgo aix LDFLAGS: -Wl,-berok
|
||||
#cgo solaris LDFLAGS: -lxnet
|
||||
#cgo illumos LDFLAGS: -lsocket
|
||||
#cgo solaris LDFLAGS: -lsocket
|
||||
|
||||
#cgo CFLAGS: -Wall -Werror
|
||||
|
||||
|
@ -10,34 +10,11 @@ package syscall
|
||||
|
||||
import "unsafe"
|
||||
|
||||
//go:cgo_import_dynamic libc_accept4 accept4 "libsocket.so"
|
||||
//go:cgo_import_dynamic libc_flock flock "libc.so"
|
||||
|
||||
//go:linkname procAccept4 libc_accept4
|
||||
//go:linkname procFlock libc_flock
|
||||
|
||||
var (
|
||||
procAccept4,
|
||||
procFlock libcFunc
|
||||
)
|
||||
|
||||
func Accept4(fd int, flags int) (int, Sockaddr, error) {
|
||||
var rsa RawSockaddrAny
|
||||
var addrlen _Socklen = SizeofSockaddrAny
|
||||
nfd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procAccept4)), 4, uintptr(fd), uintptr(unsafe.Pointer(&rsa)), uintptr(unsafe.Pointer(&addrlen)), uintptr(flags), 0, 0)
|
||||
if errno != 0 {
|
||||
return 0, nil, errno
|
||||
}
|
||||
if addrlen > SizeofSockaddrAny {
|
||||
panic("RawSockaddrAny too small")
|
||||
}
|
||||
sa, err := anyToSockaddr(&rsa)
|
||||
if err != nil {
|
||||
Close(int(nfd))
|
||||
return 0, nil, err
|
||||
}
|
||||
return int(nfd), sa, nil
|
||||
}
|
||||
var procFlock libcFunc
|
||||
|
||||
func Flock(fd int, how int) error {
|
||||
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFlock)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0)
|
||||
|
@ -71,6 +71,26 @@ func Pipe2(p []int, flags int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4
|
||||
|
||||
func Accept4(fd int, flags int) (int, Sockaddr, error) {
|
||||
var rsa RawSockaddrAny
|
||||
var addrlen _Socklen = SizeofSockaddrAny
|
||||
nfd, err := accept4(fd, &rsa, &addrlen, flags)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
if addrlen > SizeofSockaddrAny {
|
||||
panic("RawSockaddrAny too small")
|
||||
}
|
||||
sa, err := anyToSockaddr(&rsa)
|
||||
if err != nil {
|
||||
Close(nfd)
|
||||
return 0, nil, err
|
||||
}
|
||||
return nfd, sa, nil
|
||||
}
|
||||
|
||||
func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
if sa.Port < 0 || sa.Port > 0xFFFF {
|
||||
return nil, 0, EINVAL
|
||||
|
@ -8,6 +8,7 @@ package syscall
|
||||
import "unsafe"
|
||||
|
||||
//go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so"
|
||||
//go:cgo_import_dynamic libc_accept4 accept4 "libsocket.so"
|
||||
//go:cgo_import_dynamic libc_Getcwd getcwd "libc.so"
|
||||
//go:cgo_import_dynamic libc_getgroups getgroups "libc.so"
|
||||
//go:cgo_import_dynamic libc_setgroups setgroups "libc.so"
|
||||
@ -94,6 +95,7 @@ import "unsafe"
|
||||
//go:cgo_import_dynamic libc_utimensat utimensat "libc.so"
|
||||
|
||||
//go:linkname libc_pipe2 libc_pipe2
|
||||
//go:linkname libc_accept4 libc_accept4
|
||||
//go:linkname libc_Getcwd libc_Getcwd
|
||||
//go:linkname libc_getgroups libc_getgroups
|
||||
//go:linkname libc_setgroups libc_setgroups
|
||||
@ -183,6 +185,7 @@ type libcFunc uintptr
|
||||
|
||||
var (
|
||||
libc_pipe2,
|
||||
libc_accept4,
|
||||
libc_Getcwd,
|
||||
libc_getgroups,
|
||||
libc_setgroups,
|
||||
@ -281,6 +284,17 @@ func pipe2(p *[2]_C_int, flags int) (err error) {
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) {
|
||||
r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&libc_accept4)), 4, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)), uintptr(flags), 0, 0)
|
||||
fd = int(r0)
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
|
||||
|
||||
func Getcwd(buf []byte) (n int, err error) {
|
||||
var _p0 *byte
|
||||
if len(buf) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user