diff options
author | Valery Piashchynski <[email protected]> | 2021-08-19 19:38:52 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-08-19 19:38:52 +0300 |
commit | bea5916c57469cd75102cde07a7a6c62914c74f0 (patch) | |
tree | 3b5bde4c20d705b4742f1c80b9ebcc5e02372c3a /utils | |
parent | 324407b3e2d779143be65872993c4d091abb1d38 (diff) |
Add support for the IPv6
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/isolate.go | 1 | ||||
-rwxr-xr-x | utils/isolate_win.go | 1 | ||||
-rwxr-xr-x | utils/network.go | 34 | ||||
-rwxr-xr-x | utils/network_windows.go | 1 |
4 files changed, 30 insertions, 7 deletions
diff --git a/utils/isolate.go b/utils/isolate.go index 202f538c..65865ddb 100755 --- a/utils/isolate.go +++ b/utils/isolate.go @@ -1,5 +1,4 @@ //go:build !windows -// +build !windows package utils diff --git a/utils/isolate_win.go b/utils/isolate_win.go index 6b6d22e0..00f84bf4 100755 --- a/utils/isolate_win.go +++ b/utils/isolate_win.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package utils diff --git a/utils/network.go b/utils/network.go index 301e2bab..4ff41350 100755 --- a/utils/network.go +++ b/utils/network.go @@ -1,5 +1,4 @@ //go:build linux || darwin || freebsd -// +build linux darwin freebsd package utils @@ -13,6 +12,11 @@ import ( "github.com/valyala/tcplisten" ) +const ( + IPV4 string = "tcp4" + IPV6 string = "tcp6" +) + // CreateListener // - SO_REUSEPORT. This option allows linear scaling server performance // on multi-CPU servers. @@ -61,13 +65,35 @@ func createTCPListener(addr string) (net.Listener, error) { ReusePort: true, DeferAccept: true, FastOpen: true, - Backlog: 0, } - listener, err := cfg.NewListener("tcp4", addr) + + /* + Options we may have here: + 1. [::1]:8080 //ipv6 + 2. [0:0:..]:8080 //ipv6 + 3. 127.0.0.1:8080 //ipv4 + 4. :8080 //ipv4 + 5. [::]:8080 //ipv6 + */ + host, _, err := net.SplitHostPort(addr) if err != nil { return nil, err } - return listener, nil + + // consider this is IPv4 + if host == "" { + return cfg.NewListener(IPV4, addr) + } + + return cfg.NewListener(netw(net.ParseIP(host)), addr) +} + +// check if we are listening on the ipv6 or ipv4 address +func netw(addr net.IP) string { + if addr.To4() == nil { + return IPV6 + } + return IPV4 } // fileExists checks if a file exists and is not a directory before we diff --git a/utils/network_windows.go b/utils/network_windows.go index 88e0fdb6..2962b3b4 100755 --- a/utils/network_windows.go +++ b/utils/network_windows.go @@ -1,5 +1,4 @@ //go:build windows -// +build windows package utils |