mirror of
https://github.com/kemko/nomad.git
synced 2026-01-02 16:35:44 +03:00
Work around bugs in package net in Go < 1.6.
This commit is contained in:
@@ -257,12 +257,28 @@ func DefaultConfig() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
// GetListener can be used to get a new listener using a custom bind address.
|
||||
// Listener can be used to get a new listener using a custom bind address.
|
||||
// If the bind provided address is empty, the BindAddr is used instead.
|
||||
func (c *Config) Listener(proto, addr string, port int) (net.Listener, error) {
|
||||
if addr == "" {
|
||||
addr = c.BindAddr
|
||||
}
|
||||
|
||||
// Do our own range check to avoid bugs in package net.
|
||||
//
|
||||
// golang.org/issue/11715
|
||||
// golang.org/issue/13447
|
||||
//
|
||||
// Both of the above bugs were fixed by golang.org/cl/12447 which will be
|
||||
// included in Go 1.6. The error returned below is the same as what Go 1.6
|
||||
// will return.
|
||||
if 0 > port || port > 65535 {
|
||||
return nil, &net.OpError{
|
||||
Op: "listen",
|
||||
Net: proto,
|
||||
Err: &net.AddrError{Err: "invalid port", Addr: fmt.Sprint(port)},
|
||||
}
|
||||
}
|
||||
return net.Listen(proto, fmt.Sprintf("%s:%d", addr, port))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user