-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes miekg#654
- Loading branch information
Showing
4 changed files
with
126 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// +build go1.11,!windows | ||
|
||
package dns | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"syscall" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
const supportsReuseport = true | ||
|
||
func reuseportControl(network, address string, c syscall.RawConn) error { | ||
var opErr error | ||
err := c.Control(func(fd uintptr) { | ||
opErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return opErr | ||
} | ||
|
||
func listenTCP(network, addr string, reuseport bool) (net.Listener, error) { | ||
var lc net.ListenConfig | ||
if reuseport { | ||
lc.Control = reuseportControl | ||
} | ||
|
||
return lc.Listen(context.Background(), network, addr) | ||
} | ||
|
||
func listenUDP(network, addr string, reuseport bool) (net.PacketConn, error) { | ||
var lc net.ListenConfig | ||
if reuseport { | ||
lc.Control = reuseportControl | ||
} | ||
|
||
return lc.ListenPacket(context.Background(), network, addr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// +build !go1.11 windows | ||
|
||
package dns | ||
|
||
import "net" | ||
|
||
const supportsReuseport = false | ||
|
||
func listenTCP(network, addr string, reuseport bool) (net.Listener, error) { | ||
if reuseport { | ||
// TODO(tmthrgd): return an error? | ||
} | ||
|
||
return net.Listen(network, addr) | ||
} | ||
|
||
func listenUDP(network, addr string, reuseport bool) (net.PacketConn, error) { | ||
if reuseport { | ||
// TODO(tmthrgd): return an error? | ||
} | ||
|
||
return net.ListenPacket(network, addr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters