-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only compile the listener configuration logic on unix.
- Loading branch information
Showing
3 changed files
with
44 additions
and
33 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,34 @@ | ||
//go:build !windows | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"golang.org/x/sys/unix" | ||
"net" | ||
"syscall" | ||
) | ||
|
||
func newNetListener(protocol, address string) (net.Listener, error) { | ||
lc := net.ListenConfig{ | ||
Control: func(network, address string, c syscall.RawConn) error { | ||
var socketErr error | ||
err := c.Control(func(fd uintptr) { | ||
err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) | ||
if err != nil { | ||
socketErr = err | ||
} | ||
|
||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) | ||
if err != nil { | ||
socketErr = err | ||
} | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return socketErr | ||
}, | ||
} | ||
return lc.Listen(context.Background(), protocol, address) | ||
} |
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,7 @@ | ||
package server | ||
|
||
import "net" | ||
|
||
func newNetListener(protocol, address string) (net.Listener, error) { | ||
return net.Listen(protocol, address) | ||
} |