From f6980ec948dd26839fcd210dbc18c76272633fe3 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 24 Apr 2024 20:28:45 +0800 Subject: [PATCH] opt: fix compilation errors on *BSD (#593) --- .github/workflows/cross-compile-bsd.yml | 85 ++++++++++++++++++++++ acceptor_unix.go | 4 +- client_test.go | 4 +- client_unix.go | 4 +- conn_map.go | 4 +- conn_matrix.go | 4 +- conn_matrix_test.go | 4 +- connection_bsd.go | 4 +- connection_unix.go | 4 +- engine_unix.go | 4 +- eventloop_unix.go | 4 +- eventloop_unix_test.go | 4 +- go.mod | 4 +- go.sum | 8 +- internal/io/io_bsd.go | 4 +- internal/netpoll/defs_bsd_32bit.go | 4 +- internal/netpoll/defs_bsd_64bit.go | 4 +- internal/netpoll/defs_poller.go | 7 +- internal/netpoll/defs_poller_bsd.go | 24 ++++++ internal/netpoll/defs_poller_epoll.go | 3 + internal/netpoll/defs_poller_kqueue.go | 7 +- internal/netpoll/defs_poller_netbsd.go | 21 ++++++ internal/netpoll/poller_epoll_default.go | 6 +- internal/netpoll/poller_epoll_ultimate.go | 18 ++--- internal/netpoll/poller_kqueue_default.go | 42 +++++------ internal/netpoll/poller_kqueue_ultimate.go | 55 ++++++-------- internal/netpoll/poller_kqueue_wakeup.go | 55 ++++++++++++++ internal/netpoll/poller_kqueue_wakeup1.go | 62 ++++++++++++++++ internal/netpoll/poller_unix_ultimate.go | 29 ++++++++ internal/socket/fd_unix.go | 4 +- internal/socket/sock_bsd.go | 4 +- internal/socket/sock_cloexec.go | 4 +- internal/socket/sock_posix.go | 4 +- internal/socket/socket.go | 4 +- internal/socket/sockopts_posix.go | 4 +- internal/socket/sockopts_unix.go | 4 +- internal/socket/sockopts_unix1.go | 4 +- internal/socket/socktoaddr.go | 4 +- internal/socket/sys_cloexec.go | 4 +- internal/socket/tcp_socket.go | 4 +- internal/socket/udp_socket.go | 4 +- internal/socket/unix_socket.go | 4 +- listener_unix.go | 4 +- os_unix_test.go | 4 +- reactor_default.go | 4 +- reactor_ultimate.go | 4 +- 46 files changed, 401 insertions(+), 149 deletions(-) create mode 100644 .github/workflows/cross-compile-bsd.yml create mode 100644 internal/netpoll/defs_poller_bsd.go create mode 100644 internal/netpoll/defs_poller_netbsd.go create mode 100644 internal/netpoll/poller_kqueue_wakeup.go create mode 100644 internal/netpoll/poller_kqueue_wakeup1.go create mode 100644 internal/netpoll/poller_unix_ultimate.go diff --git a/.github/workflows/cross-compile-bsd.yml b/.github/workflows/cross-compile-bsd.yml new file mode 100644 index 000000000..37a65afe2 --- /dev/null +++ b/.github/workflows/cross-compile-bsd.yml @@ -0,0 +1,85 @@ +name: Cross-compile for *BSD + +on: + push: + branches: + - master + - dev + - 1.x + paths-ignore: + - '**.md' + - '**.yml' + - '**.yaml' + - '!.github/workflows/cross-compile-bsd.yml' + pull_request: + branches: + - master + - dev + - 1.x + paths-ignore: + - '**.md' + - '**.yml' + - '**.yaml' + - '!.github/workflows/cross-compile-bsd.yml' + +env: + GO111MODULE: on + GOPROXY: "https://proxy.golang.org" + +jobs: + build: + strategy: + fail-fast: false + matrix: + go: ['1.17', '1.21'] + os: + - ubuntu-latest + name: Go ${{ matrix.go }} @ ${{ matrix.os }} + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Print Go environment + id: go-env + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env + # Calculate the short SHA1 hash of the git commit + echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + echo "GO_CACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT + + - name: Cross-compiling for DragonFlyBSD + run: GOOS=dragonfly GOARCH=amd64 go build + + - name: Cross-compiling for DragonFlyBSD -tags=poll_opt,gc_opt + run: GOOS=dragonfly GOARCH=amd64 go build -tags=poll_opt,gc_opt + + - name: Cross-compiling for FreeBSD + run: GOOS=freebsd GOARCH=amd64 go build + + - name: Cross-compiling for FreeBSD -tags=poll_opt,gc_opt + run: GOOS=freebsd GOARCH=amd64 go build -tags=poll_opt,gc_opt + + - name: Cross-compiling for NetBSD + run: GOOS=netbsd GOARCH=amd64 go build + + - name: Cross-compiling for NetBSD -tags=poll_opt,gc_opt + run: GOOS=netbsd GOARCH=amd64 go build -tags=poll_opt,gc_opt + + - name: Cross-compiling for OpenBSD + run: GOOS=openbsd GOARCH=amd64 go build + + - name: Cross-compiling for OpenBSD -tags=poll_opt,gc_opt + run: GOOS=openbsd GOARCH=amd64 go build -tags=poll_opt,gc_opt diff --git a/acceptor_unix.go b/acceptor_unix.go index fe7d67cab..ae6e9a35e 100644 --- a/acceptor_unix.go +++ b/acceptor_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/client_test.go b/client_test.go index dccbf10dc..8b56f5494 100644 --- a/client_test.go +++ b/client_test.go @@ -1,5 +1,5 @@ -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin || windows -// +build linux freebsd dragonfly netbsd openbsd darwin windows +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || windows +// +build darwin dragonfly freebsd linux netbsd openbsd windows package gnet diff --git a/client_unix.go b/client_unix.go index 10bf99c07..597d73592 100644 --- a/client_unix.go +++ b/client_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/conn_map.go b/conn_map.go index e6e45a050..6b1b02aa1 100644 --- a/conn_map.go +++ b/conn_map.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && !gc_opt -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && !gc_opt +// +build darwin dragonfly freebsd linux netbsd openbsd // +build !gc_opt package gnet diff --git a/conn_matrix.go b/conn_matrix.go index 70ba4affa..6076a41fb 100644 --- a/conn_matrix.go +++ b/conn_matrix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && gc_opt -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && gc_opt +// +build darwin dragonfly freebsd linux netbsd openbsd // +build gc_opt package gnet diff --git a/conn_matrix_test.go b/conn_matrix_test.go index c081cfa67..c13e39e83 100644 --- a/conn_matrix_test.go +++ b/conn_matrix_test.go @@ -1,5 +1,5 @@ -//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && gc_opt -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && gc_opt +// +build darwin dragonfly freebsd linux netbsd openbsd // +build gc_opt package gnet diff --git a/connection_bsd.go b/connection_bsd.go index 3223f01e4..716a00180 100644 --- a/connection_bsd.go +++ b/connection_bsd.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build freebsd || dragonfly || netbsd || openbsd || darwin -// +build freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || netbsd || openbsd +// +build darwin dragonfly freebsd netbsd openbsd package gnet diff --git a/connection_unix.go b/connection_unix.go index 101a51e96..1e59f5e77 100644 --- a/connection_unix.go +++ b/connection_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/engine_unix.go b/engine_unix.go index 18f46c89d..83a1ae864 100644 --- a/engine_unix.go +++ b/engine_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/eventloop_unix.go b/eventloop_unix.go index b7530a966..d2f1c5c22 100644 --- a/eventloop_unix.go +++ b/eventloop_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/eventloop_unix_test.go b/eventloop_unix_test.go index 25e8ae64e..b9cc2121e 100644 --- a/eventloop_unix_test.go +++ b/eventloop_unix_test.go @@ -1,5 +1,5 @@ -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/go.mod b/go.mod index 9c94e27ed..02ad938c6 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ require ( github.com/stretchr/testify v1.8.4 github.com/valyala/bytebufferpool v1.0.0 go.uber.org/zap v1.21.0 // don't upgrade this one - golang.org/x/sync v0.6.0 - golang.org/x/sys v0.16.0 + golang.org/x/sync v0.7.0 + golang.org/x/sys v0.19.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) diff --git a/go.sum b/go.sum index 3a9505260..0823447e5 100644 --- a/go.sum +++ b/go.sum @@ -46,15 +46,15 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/internal/io/io_bsd.go b/internal/io/io_bsd.go index 661bb1606..c32109059 100644 --- a/internal/io/io_bsd.go +++ b/internal/io/io_bsd.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build freebsd || dragonfly || netbsd || openbsd || darwin -// +build freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || netbsd || openbsd +// +build darwin dragonfly freebsd netbsd openbsd package io diff --git a/internal/netpoll/defs_bsd_32bit.go b/internal/netpoll/defs_bsd_32bit.go index 2b0fa0b66..1a42c4a76 100644 --- a/internal/netpoll/defs_bsd_32bit.go +++ b/internal/netpoll/defs_bsd_32bit.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (freebsd || dragonfly || netbsd || openbsd || darwin) && (386 || arm || mips || mipsle) -// +build freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && (386 || arm || mips || mipsle) +// +build darwin dragonfly freebsd netbsd openbsd // +build 386 arm mips mipsle package netpoll diff --git a/internal/netpoll/defs_bsd_64bit.go b/internal/netpoll/defs_bsd_64bit.go index 1bcab7c35..7248bcceb 100644 --- a/internal/netpoll/defs_bsd_64bit.go +++ b/internal/netpoll/defs_bsd_64bit.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (freebsd || dragonfly || netbsd || openbsd || darwin) && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || riscv64) -// +build freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && (amd64 || arm64 || ppc64 || ppc64le || mips64 || mips64le || riscv64) +// +build darwin dragonfly freebsd netbsd openbsd // +build amd64 arm64 ppc64 ppc64le mips64 mips64le riscv64 package netpoll diff --git a/internal/netpoll/defs_poller.go b/internal/netpoll/defs_poller.go index 79f27d2ea..ed12ca80d 100644 --- a/internal/netpoll/defs_poller.go +++ b/internal/netpoll/defs_poller.go @@ -12,14 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package netpoll -// IOFlags represents the flags of IO events. -type IOFlags = uint16 - // PollEventHandler is the callback for I/O events notified by the poller. type PollEventHandler func(int, IOEvent, IOFlags) error diff --git a/internal/netpoll/defs_poller_bsd.go b/internal/netpoll/defs_poller_bsd.go new file mode 100644 index 000000000..772e8e4e2 --- /dev/null +++ b/internal/netpoll/defs_poller_bsd.go @@ -0,0 +1,24 @@ +// Copyright (c) 2024 The Gnet Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build darwin || dragonfly || freebsd || openbsd +// +build darwin dragonfly freebsd openbsd + +package netpoll + +// IOFlags represents the flags of IO events. +type IOFlags = uint16 + +// IOEvent is the integer type of I/O events on BSD's. +type IOEvent = int16 diff --git a/internal/netpoll/defs_poller_epoll.go b/internal/netpoll/defs_poller_epoll.go index 81501524b..423439cbe 100644 --- a/internal/netpoll/defs_poller_epoll.go +++ b/internal/netpoll/defs_poller_epoll.go @@ -19,6 +19,9 @@ package netpoll import "golang.org/x/sys/unix" +// IOFlags represents the flags of IO events. +type IOFlags = uint16 + // IOEvent is the integer type of I/O events on Linux. type IOEvent = uint32 diff --git a/internal/netpoll/defs_poller_kqueue.go b/internal/netpoll/defs_poller_kqueue.go index 89ea29ae8..af7b0adda 100644 --- a/internal/netpoll/defs_poller_kqueue.go +++ b/internal/netpoll/defs_poller_kqueue.go @@ -12,16 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build freebsd || dragonfly || netbsd || openbsd || darwin -// +build freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || netbsd || openbsd +// +build darwin dragonfly freebsd netbsd openbsd package netpoll import "golang.org/x/sys/unix" -// IOEvent is the integer type of I/O events on BSD's. -type IOEvent = int16 - const ( // InitPollEventsCap represents the initial capacity of poller event-list. InitPollEventsCap = 64 diff --git a/internal/netpoll/defs_poller_netbsd.go b/internal/netpoll/defs_poller_netbsd.go new file mode 100644 index 000000000..b29f5f9c3 --- /dev/null +++ b/internal/netpoll/defs_poller_netbsd.go @@ -0,0 +1,21 @@ +// Copyright (c) 2024 The Gnet Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package netpoll + +// IOEvent is the integer type of I/O events on BSD's. +type IOEvent = uint32 + +// IOFlags represents the flags of IO events. +type IOFlags = uint32 diff --git a/internal/netpoll/poller_epoll_default.go b/internal/netpoll/poller_epoll_default.go index 20b9cb213..12a094664 100644 --- a/internal/netpoll/poller_epoll_default.go +++ b/internal/netpoll/poller_epoll_default.go @@ -70,10 +70,8 @@ func OpenPoller() (poller *Poller, err error) { // Close closes the poller. func (p *Poller) Close() error { - if err := os.NewSyscallError("close", unix.Close(p.fd)); err != nil { - return err - } - return os.NewSyscallError("close", unix.Close(p.efd)) + _ = unix.Close(p.efd) + return os.NewSyscallError("close", unix.Close(p.fd)) } // Make the endianness of bytes compatible with more linux OSs under different processor-architectures, diff --git a/internal/netpoll/poller_epoll_ultimate.go b/internal/netpoll/poller_epoll_ultimate.go index 844914d8a..84d415f87 100644 --- a/internal/netpoll/poller_epoll_ultimate.go +++ b/internal/netpoll/poller_epoll_ultimate.go @@ -71,10 +71,8 @@ func OpenPoller() (poller *Poller, err error) { // Close closes the poller. func (p *Poller) Close() error { - if err := os.NewSyscallError("close", unix.Close(p.fd)); err != nil { - return err - } - return os.NewSyscallError("close", unix.Close(p.epa.FD)) + _ = unix.Close(p.epa.FD) + return os.NewSyscallError("close", unix.Close(p.fd)) } // Make the endianness of bytes compatible with more linux OSs under different processor-architectures, @@ -133,7 +131,7 @@ func (p *Poller) Polling() error { for i := 0; i < n; i++ { ev := &el.events[i] - pollAttachment := *(**PollAttachment)(unsafe.Pointer(&ev.data)) + pollAttachment := restorePollAttachment(unsafe.Pointer(&ev.data)) if pollAttachment.FD == p.epa.FD { // poller is awakened to run tasks in queues. doChores = true } else { @@ -210,7 +208,7 @@ func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error { if edgeTriggered { ev.events |= unix.EPOLLET } - *(**PollAttachment)(unsafe.Pointer(&ev.data)) = pa + convertPollAttachment(unsafe.Pointer(&ev.data), pa) return os.NewSyscallError("epoll_ctl add", epollCtl(p.fd, unix.EPOLL_CTL_ADD, pa.FD, &ev)) } @@ -221,7 +219,7 @@ func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error { if edgeTriggered { ev.events |= unix.EPOLLET } - *(**PollAttachment)(unsafe.Pointer(&ev.data)) = pa + convertPollAttachment(unsafe.Pointer(&ev.data), pa) return os.NewSyscallError("epoll_ctl add", epollCtl(p.fd, unix.EPOLL_CTL_ADD, pa.FD, &ev)) } @@ -232,7 +230,7 @@ func (p *Poller) AddWrite(pa *PollAttachment, edgeTriggered bool) error { if edgeTriggered { ev.events |= unix.EPOLLET } - *(**PollAttachment)(unsafe.Pointer(&ev.data)) = pa + convertPollAttachment(unsafe.Pointer(&ev.data), pa) return os.NewSyscallError("epoll_ctl add", epollCtl(p.fd, unix.EPOLL_CTL_ADD, pa.FD, &ev)) } @@ -243,7 +241,7 @@ func (p *Poller) ModRead(pa *PollAttachment, edgeTriggered bool) error { if edgeTriggered { ev.events |= unix.EPOLLET } - *(**PollAttachment)(unsafe.Pointer(&ev.data)) = pa + convertPollAttachment(unsafe.Pointer(&ev.data), pa) return os.NewSyscallError("epoll_ctl mod", epollCtl(p.fd, unix.EPOLL_CTL_MOD, pa.FD, &ev)) } @@ -254,7 +252,7 @@ func (p *Poller) ModReadWrite(pa *PollAttachment, edgeTriggered bool) error { if edgeTriggered { ev.events |= unix.EPOLLET } - *(**PollAttachment)(unsafe.Pointer(&ev.data)) = pa + convertPollAttachment(unsafe.Pointer(&ev.data), pa) return os.NewSyscallError("epoll_ctl mod", epollCtl(p.fd, unix.EPOLL_CTL_MOD, pa.FD, &ev)) } diff --git a/internal/netpoll/poller_kqueue_default.go b/internal/netpoll/poller_kqueue_default.go index 4a04c3d80..c44be9027 100644 --- a/internal/netpoll/poller_kqueue_default.go +++ b/internal/netpoll/poller_kqueue_default.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (freebsd || dragonfly || netbsd || openbsd || darwin) && !poll_opt -// +build freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && !poll_opt +// +build darwin dragonfly freebsd netbsd openbsd // +build !poll_opt package netpoll @@ -33,6 +33,7 @@ import ( // Poller represents a poller which is in charge of monitoring file-descriptors. type Poller struct { fd int + pipe []int wakeupCall int32 asyncTaskQueue queue.AsyncTaskQueue // queue with low priority urgentAsyncTaskQueue queue.AsyncTaskQueue // queue with high priority @@ -47,14 +48,10 @@ func OpenPoller() (poller *Poller, err error) { err = os.NewSyscallError("kqueue", err) return } - if _, err = unix.Kevent(poller.fd, []unix.Kevent_t{{ - Ident: 0, - Filter: unix.EVFILT_USER, - Flags: unix.EV_ADD | unix.EV_CLEAR, - }}, nil, nil); err != nil { + if err = poller.addWakeupEvent(); err != nil { _ = poller.Close() poller = nil - err = os.NewSyscallError("kevent add|clear", err) + err = os.NewSyscallError("kevent | pipe2", err) return } poller.asyncTaskQueue = queue.NewLockFreeQueue() @@ -65,15 +62,13 @@ func OpenPoller() (poller *Poller, err error) { // Close closes the poller. func (p *Poller) Close() error { + if len(p.pipe) == 2 { + _ = unix.Close(p.pipe[0]) + _ = unix.Close(p.pipe[1]) + } return os.NewSyscallError("close", unix.Close(p.fd)) } -var note = []unix.Kevent_t{{ - Ident: 0, - Filter: unix.EVFILT_USER, - Fflags: unix.NOTE_TRIGGER, -}} - // Trigger enqueues task and wakes up the poller to process pending tasks. // By default, any incoming task will enqueued into urgentAsyncTaskQueue // before the threshold of high-priority events is reached. When it happens, @@ -91,11 +86,9 @@ func (p *Poller) Trigger(priority queue.EventPriority, fn queue.TaskFunc, arg in p.urgentAsyncTaskQueue.Enqueue(task) } if atomic.CompareAndSwapInt32(&p.wakeupCall, 0, 1) { - if _, err = unix.Kevent(p.fd, note, nil, nil); err == unix.EAGAIN { - err = nil - } + err = p.wakePoller() } - return os.NewSyscallError("kevent trigger", err) + return os.NewSyscallError("kevent | write", err) } // Polling blocks the current goroutine, waiting for network-events. @@ -123,6 +116,7 @@ func (p *Poller) Polling(callback PollEventHandler) error { ev := &el.events[i] if fd := int(ev.Ident); fd == 0 { // poller is awakened to run tasks in queues doChores = true + p.drainWakeupEvent() } else { switch err = callback(fd, ev.Filter, ev.Flags); err { case nil: @@ -162,9 +156,7 @@ func (p *Poller) Polling(callback PollEventHandler) error { } atomic.StoreInt32(&p.wakeupCall, 0) if (!p.asyncTaskQueue.IsEmpty() || !p.urgentAsyncTaskQueue.IsEmpty()) && atomic.CompareAndSwapInt32(&p.wakeupCall, 0, 1) { - switch _, err = unix.Kevent(p.fd, note, nil, nil); err { - case nil, unix.EAGAIN: - default: + if err = p.wakePoller(); err != nil { doChores = true } } @@ -180,7 +172,7 @@ func (p *Poller) Polling(callback PollEventHandler) error { // AddReadWrite registers the given file-descriptor with readable and writable events to the poller. func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error { - var flags uint16 = unix.EV_ADD + var flags IOFlags = unix.EV_ADD if edgeTriggered { flags |= unix.EV_CLEAR } @@ -193,7 +185,7 @@ func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error { // AddRead registers the given file-descriptor with readable event to the poller. func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error { - var flags uint16 = unix.EV_ADD + var flags IOFlags = unix.EV_ADD if edgeTriggered { flags |= unix.EV_CLEAR } @@ -205,7 +197,7 @@ func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error { // AddWrite registers the given file-descriptor with writable event to the poller. func (p *Poller) AddWrite(pa *PollAttachment, edgeTriggered bool) error { - var flags uint16 = unix.EV_ADD + var flags IOFlags = unix.EV_ADD if edgeTriggered { flags |= unix.EV_CLEAR } @@ -225,7 +217,7 @@ func (p *Poller) ModRead(pa *PollAttachment, _ bool) error { // ModReadWrite renews the given file-descriptor with readable and writable events in the poller. func (p *Poller) ModReadWrite(pa *PollAttachment, edgeTriggered bool) error { - var flags uint16 = unix.EV_ADD + var flags IOFlags = unix.EV_ADD if edgeTriggered { flags |= unix.EV_CLEAR } diff --git a/internal/netpoll/poller_kqueue_ultimate.go b/internal/netpoll/poller_kqueue_ultimate.go index 397dad052..fc50c6521 100644 --- a/internal/netpoll/poller_kqueue_ultimate.go +++ b/internal/netpoll/poller_kqueue_ultimate.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (freebsd || dragonfly || netbsd || openbsd || darwin) && poll_opt -// +build freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || netbsd || openbsd) && poll_opt +// +build darwin dragonfly freebsd netbsd openbsd // +build poll_opt package netpoll @@ -34,6 +34,7 @@ import ( // Poller represents a poller which is in charge of monitoring file-descriptors. type Poller struct { fd int + pipe []int wakeupCall int32 asyncTaskQueue queue.AsyncTaskQueue // queue with low priority urgentAsyncTaskQueue queue.AsyncTaskQueue // queue with high priority @@ -48,14 +49,10 @@ func OpenPoller() (poller *Poller, err error) { err = os.NewSyscallError("kqueue", err) return } - if _, err = unix.Kevent(poller.fd, []unix.Kevent_t{{ - Ident: 0, - Filter: unix.EVFILT_USER, - Flags: unix.EV_ADD | unix.EV_CLEAR, - }}, nil, nil); err != nil { + if err = poller.addWakeupEvent(); err != nil { _ = poller.Close() poller = nil - err = os.NewSyscallError("kevent add|clear", err) + err = os.NewSyscallError("kevent | pipe2", err) return } poller.asyncTaskQueue = queue.NewLockFreeQueue() @@ -66,15 +63,13 @@ func OpenPoller() (poller *Poller, err error) { // Close closes the poller. func (p *Poller) Close() error { + if len(p.pipe) == 2 { + _ = unix.Close(p.pipe[0]) + _ = unix.Close(p.pipe[1]) + } return os.NewSyscallError("close", unix.Close(p.fd)) } -var note = []unix.Kevent_t{{ - Ident: 0, - Filter: unix.EVFILT_USER, - Fflags: unix.NOTE_TRIGGER, -}} - // Trigger enqueues task and wakes up the poller to process pending tasks. // By default, any incoming task will enqueued into urgentAsyncTaskQueue // before the threshold of high-priority events is reached. When it happens, @@ -92,11 +87,9 @@ func (p *Poller) Trigger(priority queue.EventPriority, fn queue.TaskFunc, arg in p.urgentAsyncTaskQueue.Enqueue(task) } if atomic.CompareAndSwapInt32(&p.wakeupCall, 0, 1) { - if _, err = unix.Kevent(p.fd, note, nil, nil); err == unix.EAGAIN { - err = nil - } + err = p.wakePoller() } - return os.NewSyscallError("kevent trigger", err) + return os.NewSyscallError("kevent | write", err) } // Polling blocks the current goroutine, waiting for network-events. @@ -124,8 +117,9 @@ func (p *Poller) Polling() error { ev := &el.events[i] if ev.Ident == 0 { // poller is awakened to run tasks in queues doChores = true + p.drainWakeupEvent() } else { - pollAttachment := (*PollAttachment)(unsafe.Pointer(ev.Udata)) + pollAttachment := restorePollAttachment(unsafe.Pointer(&ev.Udata)) switch err = pollAttachment.Callback(int(ev.Ident), ev.Filter, ev.Flags); err { case nil: case errors.ErrAcceptSocket, errors.ErrEngineShutdown: @@ -164,9 +158,7 @@ func (p *Poller) Polling() error { } atomic.StoreInt32(&p.wakeupCall, 0) if (!p.asyncTaskQueue.IsEmpty() || !p.urgentAsyncTaskQueue.IsEmpty()) && atomic.CompareAndSwapInt32(&p.wakeupCall, 0, 1) { - switch _, err = unix.Kevent(p.fd, note, nil, nil); err { - case nil, unix.EAGAIN: - default: + if err = p.wakePoller(); err != nil { doChores = true } } @@ -184,12 +176,12 @@ func (p *Poller) Polling() error { func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error { var evs [2]unix.Kevent_t evs[0].Ident = keventIdent(pa.FD) + evs[0].Filter = unix.EVFILT_READ evs[0].Flags = unix.EV_ADD if edgeTriggered { evs[0].Flags |= unix.EV_CLEAR } - evs[0].Filter = unix.EVFILT_READ - evs[0].Udata = (*byte)(unsafe.Pointer(pa)) + convertPollAttachment(unsafe.Pointer(&evs[0].Udata), pa) evs[1] = evs[0] evs[1].Filter = unix.EVFILT_WRITE _, err := unix.Kevent(p.fd, evs[:], nil, nil) @@ -200,12 +192,12 @@ func (p *Poller) AddReadWrite(pa *PollAttachment, edgeTriggered bool) error { func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error { var evs [1]unix.Kevent_t evs[0].Ident = keventIdent(pa.FD) + evs[0].Filter = unix.EVFILT_READ evs[0].Flags = unix.EV_ADD if edgeTriggered { evs[0].Flags |= unix.EV_CLEAR } - evs[0].Filter = unix.EVFILT_READ - evs[0].Udata = (*byte)(unsafe.Pointer(pa)) + convertPollAttachment(unsafe.Pointer(&evs[0].Udata), pa) _, err := unix.Kevent(p.fd, evs[:], nil, nil) return os.NewSyscallError("kevent add", err) } @@ -214,12 +206,12 @@ func (p *Poller) AddRead(pa *PollAttachment, edgeTriggered bool) error { func (p *Poller) AddWrite(pa *PollAttachment, edgeTriggered bool) error { var evs [1]unix.Kevent_t evs[0].Ident = keventIdent(pa.FD) + evs[0].Filter = unix.EVFILT_WRITE evs[0].Flags = unix.EV_ADD if edgeTriggered { evs[0].Flags |= unix.EV_CLEAR } - evs[0].Filter = unix.EVFILT_WRITE - evs[0].Udata = (*byte)(unsafe.Pointer(pa)) + convertPollAttachment(unsafe.Pointer(&evs[0].Udata), pa) _, err := unix.Kevent(p.fd, evs[:], nil, nil) return os.NewSyscallError("kevent add", err) } @@ -228,9 +220,8 @@ func (p *Poller) AddWrite(pa *PollAttachment, edgeTriggered bool) error { func (p *Poller) ModRead(pa *PollAttachment, _ bool) error { var evs [1]unix.Kevent_t evs[0].Ident = keventIdent(pa.FD) - evs[0].Flags = unix.EV_DELETE evs[0].Filter = unix.EVFILT_WRITE - evs[0].Udata = (*byte)(unsafe.Pointer(pa)) + evs[0].Flags = unix.EV_DELETE _, err := unix.Kevent(p.fd, evs[:], nil, nil) return os.NewSyscallError("kevent delete", err) } @@ -239,12 +230,12 @@ func (p *Poller) ModRead(pa *PollAttachment, _ bool) error { func (p *Poller) ModReadWrite(pa *PollAttachment, edgeTriggered bool) error { var evs [1]unix.Kevent_t evs[0].Ident = keventIdent(pa.FD) + evs[0].Filter = unix.EVFILT_WRITE evs[0].Flags = unix.EV_ADD if edgeTriggered { evs[0].Flags |= unix.EV_CLEAR } - evs[0].Filter = unix.EVFILT_WRITE - evs[0].Udata = (*byte)(unsafe.Pointer(pa)) + convertPollAttachment(unsafe.Pointer(&evs[0].Udata), pa) _, err := unix.Kevent(p.fd, evs[:], nil, nil) return os.NewSyscallError("kevent add", err) } diff --git a/internal/netpoll/poller_kqueue_wakeup.go b/internal/netpoll/poller_kqueue_wakeup.go new file mode 100644 index 000000000..2f9f93298 --- /dev/null +++ b/internal/netpoll/poller_kqueue_wakeup.go @@ -0,0 +1,55 @@ +// Copyright (c) 2024 The Gnet Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build darwin || dragonfly || freebsd +// +build darwin dragonfly freebsd + +package netpoll + +import ( + "golang.org/x/sys/unix" + + "github.com/panjf2000/gnet/v2/pkg/logging" +) + +func (p *Poller) addWakeupEvent() error { + _, err := unix.Kevent(p.fd, []unix.Kevent_t{{ + Ident: 0, + Filter: unix.EVFILT_USER, + Flags: unix.EV_ADD | unix.EV_CLEAR, + }}, nil, nil) + return err +} + +func (p *Poller) wakePoller() error { +retry: + _, err := unix.Kevent(p.fd, []unix.Kevent_t{{ + Ident: 0, + Filter: unix.EVFILT_USER, + Fflags: unix.NOTE_TRIGGER, + }}, nil, nil) + if err == nil { + return nil + } + if err == unix.EINTR { + // All changes contained in the changelist should have been applied + // before returning EINTR. But let's be skeptical and retry it anyway, + // to make a 100% commitment. + goto retry + } + logging.Warnf("failed to wake up the poller: %v", err) + return err +} + +func (p *Poller) drainWakeupEvent() {} diff --git a/internal/netpoll/poller_kqueue_wakeup1.go b/internal/netpoll/poller_kqueue_wakeup1.go new file mode 100644 index 000000000..4505b5087 --- /dev/null +++ b/internal/netpoll/poller_kqueue_wakeup1.go @@ -0,0 +1,62 @@ +// Copyright (c) 2024 The Gnet Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build netbsd || openbsd +// +build netbsd openbsd + +package netpoll + +import ( + "golang.org/x/sys/unix" + + "github.com/panjf2000/gnet/v2/pkg/logging" +) + +// TODO(panjf2000): NetBSD didn't implement EVFILT_USER for user-established events +// until NetBSD 10.0, check out https://www.netbsd.org/releases/formal-10/NetBSD-10.0.html +// Therefore we use the pipe to wake up the kevent on NetBSD at this point. Get back here +// and switch to EVFILT_USER when we bump up the minimal requirement of NetBSD to 10.0. +// Alternatively, maybe we can use EVFILT_USER on the NetBSD by checking the kernel version +// via uname(3) and fall back to the pipe if the kernel version is older than 10.0. + +func (p *Poller) addWakeupEvent() error { + p.pipe = make([]int, 2) + if err := unix.Pipe2(p.pipe[:], unix.O_NONBLOCK|unix.O_CLOEXEC); err != nil { + logging.Fatalf("failed to create pipe for wakeup event: %v", err) + } + _, err := unix.Kevent(p.fd, []unix.Kevent_t{{ + Ident: uint64(p.pipe[0]), + Filter: unix.EVFILT_READ, + Flags: unix.EV_ADD, + }}, nil, nil) + return err +} + +func (p *Poller) wakePoller() error { +retry: + _, err := unix.Write(p.pipe[1], []byte("x")) + if err == nil || err == unix.EAGAIN { + return nil + } + if err == unix.EINTR { + goto retry + } + logging.Warnf("failed to write to the wakeup pipe: %v", err) + return err +} + +func (p *Poller) drainWakeupEvent() { + var buf [8]byte + _, _ = unix.Read(p.pipe[0], buf[:]) +} diff --git a/internal/netpoll/poller_unix_ultimate.go b/internal/netpoll/poller_unix_ultimate.go new file mode 100644 index 000000000..7404e77bb --- /dev/null +++ b/internal/netpoll/poller_unix_ultimate.go @@ -0,0 +1,29 @@ +// Copyright (c) 2024 The Gnet Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && poll_opt +// +build darwin dragonfly freebsd linux netbsd openbsd +// +build poll_opt + +package netpoll + +import "unsafe" + +func convertPollAttachment(ptr unsafe.Pointer, attachment *PollAttachment) { + *(**PollAttachment)(ptr) = attachment +} + +func restorePollAttachment(ptr unsafe.Pointer) *PollAttachment { + return *(**PollAttachment)(ptr) +} diff --git a/internal/socket/fd_unix.go b/internal/socket/fd_unix.go index 82de8ce27..7b89591d9 100644 --- a/internal/socket/fd_unix.go +++ b/internal/socket/fd_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/sock_bsd.go b/internal/socket/sock_bsd.go index 6c9de5627..9d97ef417 100644 --- a/internal/socket/sock_bsd.go +++ b/internal/socket/sock_bsd.go @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build freebsd || dragonfly || netbsd || openbsd || darwin -// +build freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || netbsd || openbsd +// +build darwin dragonfly freebsd netbsd openbsd package socket diff --git a/internal/socket/sock_cloexec.go b/internal/socket/sock_cloexec.go index 4be0813a1..334ad0a3b 100644 --- a/internal/socket/sock_cloexec.go +++ b/internal/socket/sock_cloexec.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd -// +build linux freebsd dragonfly netbsd openbsd +//go:build dragonfly || freebsd || linux +// +build dragonfly freebsd linux package socket diff --git a/internal/socket/sock_posix.go b/internal/socket/sock_posix.go index 5235c6406..8b7dd24c4 100644 --- a/internal/socket/sock_posix.go +++ b/internal/socket/sock_posix.go @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/socket.go b/internal/socket/socket.go index e49f143f3..a6d9a9448 100644 --- a/internal/socket/socket.go +++ b/internal/socket/socket.go @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd // Package socket provides functions that return fd and net.Addr based on // given the protocol and address with a SO_REUSEPORT option set to the socket. diff --git a/internal/socket/sockopts_posix.go b/internal/socket/sockopts_posix.go index 1280285f2..61fc8d31f 100644 --- a/internal/socket/sockopts_posix.go +++ b/internal/socket/sockopts_posix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/sockopts_unix.go b/internal/socket/sockopts_unix.go index 1d1a2d559..4b63d8389 100644 --- a/internal/socket/sockopts_unix.go +++ b/internal/socket/sockopts_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd -// +build linux freebsd dragonfly netbsd +//go:build dragonfly || freebsd || linux || netbsd +// +build dragonfly freebsd linux netbsd package socket diff --git a/internal/socket/sockopts_unix1.go b/internal/socket/sockopts_unix1.go index 0f7be1da9..d4c666f95 100644 --- a/internal/socket/sockopts_unix1.go +++ b/internal/socket/sockopts_unix1.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || dragonfly || netbsd || openbsd || darwin -// +build linux dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || linux || netbsd || openbsd +// +build darwin dragonfly linux netbsd openbsd package socket diff --git a/internal/socket/socktoaddr.go b/internal/socket/socktoaddr.go index 36caa6f9c..068a37213 100644 --- a/internal/socket/socktoaddr.go +++ b/internal/socket/socktoaddr.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/sys_cloexec.go b/internal/socket/sys_cloexec.go index b526c100d..abd4ee378 100644 --- a/internal/socket/sys_cloexec.go +++ b/internal/socket/sys_cloexec.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build darwin -// +build darwin +//go:build darwin || netbsd || openbsd +// +build darwin netbsd openbsd package socket diff --git a/internal/socket/tcp_socket.go b/internal/socket/tcp_socket.go index 337b13c65..21d4af32e 100644 --- a/internal/socket/tcp_socket.go +++ b/internal/socket/tcp_socket.go @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/udp_socket.go b/internal/socket/udp_socket.go index 10c3ba304..6205c986b 100644 --- a/internal/socket/udp_socket.go +++ b/internal/socket/udp_socket.go @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/internal/socket/unix_socket.go b/internal/socket/unix_socket.go index b999aaf06..688672d09 100644 --- a/internal/socket/unix_socket.go +++ b/internal/socket/unix_socket.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package socket diff --git a/listener_unix.go b/listener_unix.go index e2d497b61..18fde857a 100644 --- a/listener_unix.go +++ b/listener_unix.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/os_unix_test.go b/os_unix_test.go index f3d0f0724..0612cfd06 100644 --- a/os_unix_test.go +++ b/os_unix_test.go @@ -1,5 +1,5 @@ -//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd +// +build darwin dragonfly freebsd linux netbsd openbsd package gnet diff --git a/reactor_default.go b/reactor_default.go index a8935c879..8927f471e 100644 --- a/reactor_default.go +++ b/reactor_default.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && !poll_opt -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && !poll_opt +// +build darwin dragonfly freebsd linux netbsd openbsd // +build !poll_opt package gnet diff --git a/reactor_ultimate.go b/reactor_ultimate.go index 08ab1c8c6..ce307f7c1 100644 --- a/reactor_ultimate.go +++ b/reactor_ultimate.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && poll_opt -// +build linux freebsd dragonfly netbsd openbsd darwin +//go:build (darwin || dragonfly || freebsd || linux || netbsd || openbsd) && poll_opt +// +build darwin dragonfly freebsd linux netbsd openbsd // +build poll_opt package gnet