From 7dc8559f1c2ec37e551f652f2dba2816b5956379 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sun, 16 Jan 2022 22:44:09 +0000 Subject: [PATCH] add socksopt rxtxbuf for windows --- transport/internet/sockopt_windows.go | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/transport/internet/sockopt_windows.go b/transport/internet/sockopt_windows.go index 0fed34db7..604309feb 100644 --- a/transport/internet/sockopt_windows.go +++ b/transport/internet/sockopt_windows.go @@ -1,6 +1,9 @@ package internet -import "syscall" +import ( + "golang.org/x/sys/windows" + "syscall" +) const ( TCP_FASTOPEN = 15 // nolint: revive,stylecheck @@ -32,6 +35,18 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf } } + if config.SocketTxBufSize != 0 { + if err := windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_SNDBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_SNDBUF").Base(err) + } + } + + if config.SocketRxBufSize != 0 { + if err := windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_RCVBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_RCVBUF").Base(err) + } + } + return nil } @@ -47,6 +62,18 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) } } + if config.SocketTxBufSize != 0 { + if err := windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_SNDBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_SNDBUF").Base(err) + } + } + + if config.SocketRxBufSize != 0 { + if err := windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_RCVBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_RCVBUF").Base(err) + } + } + return nil }