mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-10-08 19:06:14 -08:00
* chore(go): use lowercase module import path * ci: scope checks for Go module changes
39 lines
927 B
Go
39 lines
927 B
Go
//go:build windows
|
|
|
|
package netstd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/easytier/easytier/easytier-go/platform"
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func applyTCPSocketOptions(
|
|
descriptor uintptr,
|
|
network string,
|
|
options platform.TCPBindOptions,
|
|
) error {
|
|
reuseAddr := options.ReuseAddr
|
|
if options.ReusePort {
|
|
if reuseAddr != nil && !*reuseAddr {
|
|
return fmt.Errorf("TCP reuse_port requires reuse_addr on Windows")
|
|
}
|
|
enabled := true
|
|
reuseAddr = &enabled
|
|
}
|
|
if reuseAddr != nil {
|
|
if err := windows.SetsockoptInt(windows.Handle(descriptor),
|
|
windows.SOL_SOCKET, windows.SO_REUSEADDR, boolInt(*reuseAddr)); err != nil {
|
|
return fmt.Errorf("set TCP SO_REUSEADDR: %w", err)
|
|
}
|
|
}
|
|
if options.OnlyV6 && network == "tcp6" {
|
|
if err := windows.SetsockoptInt(windows.Handle(descriptor),
|
|
windows.IPPROTO_IPV6, windows.IPV6_V6ONLY, 1); err != nil {
|
|
return fmt.Errorf("set TCP IPV6_V6ONLY: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|