net_windows.go

 1//go:build windows
 2// +build windows
 3
 4package server
 5
 6import (
 7	"net"
 8
 9	"github.com/Microsoft/go-winio"
10)
11
12// listen binds a net.Listener on the given network and address.
13//
14// On Windows there is no Unix-socket stale-file recovery to perform,
15// so removedStale is always false. The signature matches the
16// non-Windows implementation so callers can use a single code path.
17func listen(network, address string) (net.Listener, bool, error) {
18	switch network {
19	case "npipe":
20		cfg := &winio.PipeConfig{
21			MessageMode:      true,
22			InputBufferSize:  65536,
23			OutputBufferSize: 65536,
24		}
25		ln, err := winio.ListenPipe(address, cfg)
26		if err != nil {
27			return nil, false, err
28		}
29		return ln, false, nil
30	default:
31		ln, err := net.Listen(network, address) //nolint:noctx
32		if err != nil {
33			return nil, false, err
34		}
35		return ln, false, nil
36	}
37}