From 3b8343af379c3bc9212c562a49bc1d1add12c060 Mon Sep 17 00:00:00 2001 From: xqzr <34030394+xqzr@users.noreply.github.com> Date: Tue, 1 Apr 2025 01:38:27 +0800 Subject: [PATCH] Sockopt: Add Windows `TCP_MAXSEG` #2002 --- transport/internet/sockopt_windows.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index cbd3b41e..ecae807a 100644 --- a/transport/internet/sockopt_windows.go +++ b/transport/internet/sockopt_windows.go @@ -16,6 +16,7 @@ const ( IP_MULTICAST_IF = 9 IPV6_MULTICAST_IF = 9 IPV6_V6ONLY = 27 + TCP_MAXSEG = 4 ) func setTFO(fd syscall.Handle, tfo int) error { @@ -70,6 +71,11 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf return errors.New("failed to unset SO_KEEPALIVE", err) } } + if config.TcpMaxSeg > 0 { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_TCP, syscall.TCP_MAXSEG, int(config.TcpMaxSeg)); err != nil { + return errors.New("failed to set TCP_MAXSEG", err) + } + } } return nil @@ -89,6 +95,11 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) return errors.New("failed to unset SO_KEEPALIVE", err) } } + if config.TcpMaxSeg > 0 { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.IPPROTO_TCP, syscall.TCP_MAXSEG, int(config.TcpMaxSeg)); err != nil { + return errors.New("failed to set TCP_MAXSEG", err) + } + } } if config.V6Only {