Debian Codegraph @

reuseport/reuseport_windows.go

raw
1 package reuseport
2
3 import (
4 "context"
5 "net"
6 "syscall"
7
8 "golang.org/x/sys/windows"
9 )
10
11 var listenConfig = net.ListenConfig{
12 Control: func(network, address string, c syscall.RawConn) (err error) {
13 return c.Control(func(fd uintptr) {
14 err = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
15 })
16 },
17 }
18
19 // Listen returns TCP listener with SO_REUSEADDR option set.
20 //
21 // SO_REUSEPORT is not supported on Windows, so SO_REUSEADDR is used as an
22 // approximation. Unlike POSIX SO_REUSEPORT, Windows SO_REUSEADDR does not
23 // provide same-user or same-group isolation between processes that bind the
24 // same address.
25 func Listen(network, addr string) (net.Listener, error) {
26 return listenConfig.Listen(context.Background(), network, addr)
27 }