diff --git a/reuseport/reuseport.go b/reuseport/reuseport.go index 191fe64103..85c7d65d0d 100644 --- a/reuseport/reuseport.go +++ b/reuseport/reuseport.go @@ -1,4 +1,4 @@ -// +build linux darwin dragonfly freebsd netbsd openbsd rumprun +// +build !windows // Package reuseport provides TCP net.Listener with SO_REUSEPORT support. // @@ -9,23 +9,12 @@ package reuseport import ( - "fmt" "net" "strings" "github.com/valyala/tcplisten" ) -// ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT. -type ErrNoReusePort struct { - err error -} - -// Error implements error interface. -func (e *ErrNoReusePort) Error() string { - return fmt.Sprintf("The OS doesn't support SO_REUSEPORT: %s", e.err) -} - // Listen returns TCP listener with SO_REUSEPORT option set. // // The returned listener tries enabling the following TCP options, which usually diff --git a/reuseport/reuseport_error.go b/reuseport/reuseport_error.go new file mode 100644 index 0000000000..3e29d42ae7 --- /dev/null +++ b/reuseport/reuseport_error.go @@ -0,0 +1,15 @@ +package reuseport + +import ( + "fmt" +) + +// ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT. +type ErrNoReusePort struct { + err error +} + +// Error implements error interface. +func (e *ErrNoReusePort) Error() string { + return fmt.Sprintf("The OS doesn't support SO_REUSEPORT: %s", e.err) +} diff --git a/reuseport/reuseport_test.go b/reuseport/reuseport_test.go index e781ff11f3..7763d3feb4 100644 --- a/reuseport/reuseport_test.go +++ b/reuseport/reuseport_test.go @@ -1,3 +1,5 @@ +// +build !windows + package reuseport import ( diff --git a/reuseport/reuseport_windows.go b/reuseport/reuseport_windows.go new file mode 100644 index 0000000000..8137eb5ba0 --- /dev/null +++ b/reuseport/reuseport_windows.go @@ -0,0 +1,11 @@ +package reuseport + +import ( + "fmt" + "net" +) + +// Listen always returns ErrNoReusePort on Windows +func Listen(network, addr string) (net.Listener, error) { + return nil, &ErrNoReusePort{fmt.Errorf("Not supported on Windows")} +} diff --git a/reuseport/reuseport_windows_test.go b/reuseport/reuseport_windows_test.go new file mode 100644 index 0000000000..934526730f --- /dev/null +++ b/reuseport/reuseport_windows_test.go @@ -0,0 +1,18 @@ +// +build windows + +package reuseport + +import ( + "testing" +) + +func TestListen(t *testing.T) { + _, err := Listen("tcp6", "[::1]:10082") + if err == nil { + t.Fatalf("unexpected non-error creating listener") + } + + if _, errnoreuseport := err.(*ErrNoReusePort); !errnoreuseport { + t.Fatalf("unexpected error creating listener: %s", err) + } +}