-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use strings.TrimSuffix in ListenAndServe for TLS This replaces the if/else statements with something simpler. Interestingly, the first pull request I submitted to this library was to fix the tcp6-tls case way back in 4744e91. * Add SO_REUSEPORT implementation Fixes #654 * Rename Reuseport field to ReusePort * Rename supportsReuseport to match ReusePort * Rename listenUDP and listenTCP file to listen_*.go
- Loading branch information
Showing
4 changed files
with
127 additions
and
19 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
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
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