Skip to content

Commit 3e00bd0

Browse files
tklausergopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Tobias Klauser <[email protected]> Reviewed-by: Benny Siegert <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 0537a74 commit 3e00bd0

11 files changed

+43
-32
lines changed

src/internal/poll/hook_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
5+
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
66

77
package poll
88

src/internal/poll/sock_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// This file implements accept for platforms that provide a fast path for
66
// setting SetNonblock and CloseOnExec.
77

8-
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
8+
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
99

1010
package poll
1111

src/internal/poll/sys_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// This file implements accept for platforms that do not provide a fast path for
66
// setting SetNonblock and CloseOnExec.
77

8-
//go:build aix || darwin || (js && wasm) || (solaris && !illumos)
8+
//go:build aix || darwin || (js && wasm)
99

1010
package poll
1111

src/net/internal/socktest/sys_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
5+
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
66

77
package socktest
88

src/net/main_cloexec_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
5+
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
66

77
package net
88

src/net/sock_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// This file implements sysSocket for platforms that provide a fast path for
66
// setting SetNonblock and CloseOnExec.
77

8-
//go:build dragonfly || freebsd || illumos || linux || netbsd || openbsd
8+
//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris
99

1010
package net
1111

src/net/sys_cloexec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// This file implements sysSocket for platforms that do not provide a fast path
66
// for setting SetNonblock and CloseOnExec.
77

8-
//go:build aix || darwin || (solaris && !illumos)
8+
//go:build aix || darwin
99

1010
package net
1111

src/runtime/cgo/cgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ package cgo
2121
#cgo openbsd LDFLAGS: -lpthread
2222
#cgo aix LDFLAGS: -Wl,-berok
2323
#cgo solaris LDFLAGS: -lxnet
24-
#cgo illumos LDFLAGS: -lsocket
24+
#cgo solaris LDFLAGS: -lsocket
2525
2626
#cgo CFLAGS: -Wall -Werror
2727

src/syscall/syscall_illumos.go

+1-24
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,11 @@ package syscall
1010

1111
import "unsafe"
1212

13-
//go:cgo_import_dynamic libc_accept4 accept4 "libsocket.so"
1413
//go:cgo_import_dynamic libc_flock flock "libc.so"
1514

16-
//go:linkname procAccept4 libc_accept4
1715
//go:linkname procFlock libc_flock
1816

19-
var (
20-
procAccept4,
21-
procFlock libcFunc
22-
)
23-
24-
func Accept4(fd int, flags int) (int, Sockaddr, error) {
25-
var rsa RawSockaddrAny
26-
var addrlen _Socklen = SizeofSockaddrAny
27-
nfd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procAccept4)), 4, uintptr(fd), uintptr(unsafe.Pointer(&rsa)), uintptr(unsafe.Pointer(&addrlen)), uintptr(flags), 0, 0)
28-
if errno != 0 {
29-
return 0, nil, errno
30-
}
31-
if addrlen > SizeofSockaddrAny {
32-
panic("RawSockaddrAny too small")
33-
}
34-
sa, err := anyToSockaddr(&rsa)
35-
if err != nil {
36-
Close(int(nfd))
37-
return 0, nil, err
38-
}
39-
return int(nfd), sa, nil
40-
}
17+
var procFlock libcFunc
4118

4219
func Flock(fd int, how int) error {
4320
_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFlock)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0)

src/syscall/syscall_solaris.go

+20
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ func Pipe2(p []int, flags int) error {
7171
return err
7272
}
7373

74+
//sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4
75+
76+
func Accept4(fd int, flags int) (int, Sockaddr, error) {
77+
var rsa RawSockaddrAny
78+
var addrlen _Socklen = SizeofSockaddrAny
79+
nfd, err := accept4(fd, &rsa, &addrlen, flags)
80+
if err != nil {
81+
return 0, nil, err
82+
}
83+
if addrlen > SizeofSockaddrAny {
84+
panic("RawSockaddrAny too small")
85+
}
86+
sa, err := anyToSockaddr(&rsa)
87+
if err != nil {
88+
Close(nfd)
89+
return 0, nil, err
90+
}
91+
return nfd, sa, nil
92+
}
93+
7494
func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
7595
if sa.Port < 0 || sa.Port > 0xFFFF {
7696
return nil, 0, EINVAL

src/syscall/zsyscall_solaris_amd64.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)