diff --git a/README.md b/README.md index cf45bddd3..de52d9e80 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@
- + -
+

English | [πŸ‡¨πŸ‡³δΈ­ζ–‡](README_ZH.md) diff --git a/README_ZH.md b/README_ZH.md index e53f0efc9..4986d5ff9 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -3,14 +3,14 @@
- + -
+

[θ‹±ζ–‡](README.md) | πŸ‡¨πŸ‡³δΈ­ζ–‡ diff --git a/acceptor_unix.go b/acceptor_unix.go index 6cb53f1af..104c0baab 100644 --- a/acceptor_unix.go +++ b/acceptor_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package gnet diff --git a/acceptor_windows.go b/acceptor_windows.go index 6b832b480..54a4a7cfb 100644 --- a/acceptor_windows.go +++ b/acceptor_windows.go @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build windows - package gnet import ( diff --git a/connection_unix.go b/connection_unix.go index b14107cc2..47fac37cf 100644 --- a/connection_unix.go +++ b/connection_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package gnet diff --git a/connection_windows.go b/connection_windows.go index 10249e1a9..a96c45958 100644 --- a/connection_windows.go +++ b/connection_windows.go @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build windows - package gnet import ( diff --git a/eventloop_unix.go b/eventloop_unix.go index db8652b07..39d6bc8c9 100644 --- a/eventloop_unix.go +++ b/eventloop_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package gnet diff --git a/eventloop_windows.go b/eventloop_windows.go index 5a9ab1899..dbcf21c21 100644 --- a/eventloop_windows.go +++ b/eventloop_windows.go @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build windows - package gnet import ( diff --git a/internal/netpoll/kqueue.go b/internal/netpoll/kqueue.go index dfb3ec618..3ff18caac 100644 --- a/internal/netpoll/kqueue.go +++ b/internal/netpoll/kqueue.go @@ -3,7 +3,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -// +build darwin netbsd freebsd openbsd dragonfly +// +build freebsd dragonfly darwin package netpoll diff --git a/internal/netpoll/kqueue_events.go b/internal/netpoll/kqueue_events.go index f6f7b9533..9d1ec4fcd 100644 --- a/internal/netpoll/kqueue_events.go +++ b/internal/netpoll/kqueue_events.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. -// +build darwin netbsd freebsd openbsd dragonfly +// +build freebsd dragonfly darwin package netpoll diff --git a/internal/netpoll/netpoll_stub.go b/internal/netpoll/netpoll_stub.go deleted file mode 100644 index f43acfe82..000000000 --- a/internal/netpoll/netpoll_stub.go +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2019 Andy Pan. All rights reserved. -// Copyright 2017 Joshua J Baker. All rights reserved. -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file. - -// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!windows - -package netpoll - -import ( - "errors" - "net" -) - -// SetKeepAlive sets the keepalive for the connection. -func SetKeepAlive(fd, secs int) error { - // OpenBSD has no user-settable per-socket TCP keepalive options. - return nil -} - -// ReusePortListenPacket returns a net.PacketConn for UDP. -func ReusePortListenPacket(proto, addr string) (net.PacketConn, error) { - return nil, errors.New("SO_REUSEPORT/SO_REUSEADDR is not supported on this platform") -} - -// ReusePortListen returns a net.Listener for TCP. -func ReusePortListen(proto, addr string) (net.Listener, error) { - return nil, errors.New("SO_REUSEPORT/SO_REUSEADDR is not supported on this platform") -} diff --git a/internal/netpoll/netpoll_unix.go b/internal/netpoll/netpoll_unix.go index 74a2b29c0..277a4daca 100644 --- a/internal/netpoll/netpoll_unix.go +++ b/internal/netpoll/netpoll_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux netbsd freebsd dragonfly +// +build linux freebsd dragonfly package netpoll diff --git a/internal/netpoll/socktoaddr.go b/internal/netpoll/socktoaddr.go index db0f7571f..3545768d7 100644 --- a/internal/netpoll/socktoaddr.go +++ b/internal/netpoll/socktoaddr.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package netpoll diff --git a/internal/reuseport/reuseport.go b/internal/reuseport/reuseport.go index 2468ed5dd..42af46e26 100644 --- a/internal/reuseport/reuseport.go +++ b/internal/reuseport/reuseport.go @@ -17,7 +17,7 @@ // Package reuseport provides a function that returns fd and net.Listener powered // by a net.FileListener with a SO_REUSEPORT option set to the socket. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package reuseport diff --git a/internal/reuseport/reuseport_bsd.go b/internal/reuseport/reuseport_bsd.go index 5b1d887b6..2e35ccbee 100644 --- a/internal/reuseport/reuseport_bsd.go +++ b/internal/reuseport/reuseport_bsd.go @@ -14,7 +14,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// +build darwin netbsd freebsd openbsd dragonfly +// +build freebsd dragonfly darwin package reuseport @@ -34,10 +34,6 @@ func maxListenerBacklog() int { n, err = unix.SysctlUint32("kern.ipc.somaxconn") case "freebsd": n, err = unix.SysctlUint32("kern.ipc.soacceptqueue") - case "netbsd": - // NOTE: NetBSD has no somaxconn-like kernel state so far - case "openbsd": - n, err = unix.SysctlUint32("kern.somaxconn") } if n == 0 || err != nil { return unix.SOMAXCONN diff --git a/internal/reuseport/sock_cloexec.go b/internal/reuseport/sock_cloexec.go index 394bf2ec1..81e62a5ef 100644 --- a/internal/reuseport/sock_cloexec.go +++ b/internal/reuseport/sock_cloexec.go @@ -13,7 +13,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// +build linux netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly package reuseport diff --git a/internal/reuseport/tcp.go b/internal/reuseport/tcp.go index 0a3901062..0dc316324 100644 --- a/internal/reuseport/tcp.go +++ b/internal/reuseport/tcp.go @@ -14,7 +14,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package reuseport diff --git a/internal/reuseport/udp.go b/internal/reuseport/udp.go index 3ff6d8226..1975df181 100644 --- a/internal/reuseport/udp.go +++ b/internal/reuseport/udp.go @@ -14,7 +14,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package reuseport diff --git a/internal/reuseport/uds.go b/internal/reuseport/uds.go index 7666f4002..7bd1d6b3e 100644 --- a/internal/reuseport/uds.go +++ b/internal/reuseport/uds.go @@ -13,7 +13,7 @@ // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package reuseport diff --git a/listener_unix.go b/listener_unix.go index 0a5028719..a799aaa08 100644 --- a/listener_unix.go +++ b/listener_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package gnet diff --git a/listener_windows.go b/listener_windows.go index be982d569..8be0788eb 100644 --- a/listener_windows.go +++ b/listener_windows.go @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build windows - package gnet import ( diff --git a/loop_bsd.go b/loop_bsd.go index d11e506dd..33869a80c 100644 --- a/loop_bsd.go +++ b/loop_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build darwin netbsd freebsd openbsd dragonfly +// +build freebsd dragonfly darwin package gnet diff --git a/reactor_bsd.go b/reactor_bsd.go index fd5922a4b..1bc6a2ba0 100644 --- a/reactor_bsd.go +++ b/reactor_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build darwin netbsd freebsd openbsd dragonfly +// +build freebsd dragonfly darwin package gnet diff --git a/server_stub.go b/server_stub.go index 840071d03..b9b081575 100644 --- a/server_stub.go +++ b/server_stub.go @@ -3,12 +3,10 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build !darwin,!netbsd,!freebsd,!openbsd,!dragonfly,!linux,!windows +// +build !linux,!freebsd,!dragonfly,!darwin,!windows package gnet -import "net" - type server struct { subEventLoopSet loadBalancer // event-loops for handling events } @@ -18,19 +16,23 @@ type eventloop struct { } type listener struct { - ln net.Listener - pconn net.PacketConn - lnaddr net.Addr + reusePort bool addr, network string } -func (ln *listener) renormalize() error { +func (ln *listener) normalize() error { return nil } func (ln *listener) close() { } -func serve(eventHandler EventHandler, listeners *listener, options *Options) error { +func initListener(network, addr string, reusePort bool) (l *listener, err error) { + l = &listener{network: network, addr: addr, reusePort: reusePort} + err = l.normalize() + return +} + +func serve(_ EventHandler, _ *listener, _ *Options) error { return ErrUnsupportedPlatform } diff --git a/server_unix.go b/server_unix.go index 4495a1e8e..3e88d9947 100644 --- a/server_unix.go +++ b/server_unix.go @@ -3,7 +3,7 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build linux darwin netbsd freebsd openbsd dragonfly +// +build linux freebsd dragonfly darwin package gnet diff --git a/server_windows.go b/server_windows.go index da1b3d875..9889dce9c 100644 --- a/server_windows.go +++ b/server_windows.go @@ -3,8 +3,6 @@ // Use of this source code is governed by an MIT-style // license that can be found in the LICENSE file. -// +build windows - package gnet import (