Comment new parseLiteners function.
This commit is contained in:
parent
6116a6cb02
commit
7b86bec825
1 changed files with 9 additions and 3 deletions
12
server.go
12
server.go
|
@ -766,18 +766,22 @@ func (s *server) ScheduleShutdown(duration time.Duration) {
|
|||
}()
|
||||
}
|
||||
|
||||
// parseListeners splits the list of listen addresses passed in addrs into
|
||||
// IPv4 and IPv6 slices and returns them. This allows easy creation of the
|
||||
// listeners on the correct interface "tcp4" and "tcp6". It also, properly
|
||||
// detects addresses which apply to "all interfaces" and adds the address to
|
||||
// both slices.
|
||||
func parseListeners(addrs []string) ([]string, []string, error) {
|
||||
ipv4ListenAddrs := make([]string, 0, len(cfg.Listeners)*2)
|
||||
ipv6ListenAddrs := make([]string, 0, len(cfg.Listeners)*2)
|
||||
for _, addr := range cfg.Listeners {
|
||||
host, _, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
// shouldn't happen, should have already been normalized.
|
||||
// Shouldn't happen due to already being normalized.
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Empty host or host of * on plan9 is both IPv4 and
|
||||
// IPv6.
|
||||
// Empty host or host of * on plan9 is both IPv4 and IPv6.
|
||||
if host == "" || (host == "*" && runtime.GOOS == "plan9") {
|
||||
ipv4ListenAddrs = append(ipv4ListenAddrs, addr)
|
||||
ipv6ListenAddrs = append(ipv6ListenAddrs, addr)
|
||||
|
@ -790,6 +794,8 @@ func parseListeners(addrs []string) ([]string, []string, error) {
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
// To4 returns nil when the IP is not an IPv4 address, so use
|
||||
// this determine the address type.
|
||||
if ip.To4() == nil {
|
||||
ipv6ListenAddrs = append(ipv6ListenAddrs, addr)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue