mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Add stub/wrapper for reuseport.Listen on Windows platforms (#638)
* Create Windows stub for reuseport.Listen
This commit is contained in:
committed by
Erik Dubbelboer
parent
1241ed7a91
commit
8ce231e840
+1
-12
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// +build !windows
|
||||
|
||||
package reuseport
|
||||
|
||||
import (
|
||||
|
||||
@@ -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")}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user