From 1a35c1dc695c3742979681d31b0572f040eaa2c1 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sun, 16 Jan 2022 22:45:40 +0000 Subject: [PATCH] add socksopt rxtxbuf for freebsd --- transport/internet/sockopt_freebsd.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/transport/internet/sockopt_freebsd.go b/transport/internet/sockopt_freebsd.go index 37b2d369e..525d2b0a2 100644 --- a/transport/internet/sockopt_freebsd.go +++ b/transport/internet/sockopt_freebsd.go @@ -170,6 +170,19 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf } } } + + if config.SocketTxBufSize != 0 { + if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_SNDBUF/SO_SNDBUFFORCE").Base(err) + } + } + + if config.SocketRxBufSize != 0 { + if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUF, int(config.SocketRxBufSize)); err != nil { + return newError("failed to set SO_RCVBUF/SO_RCVBUFFORCE").Base(err) + } + } + return nil } @@ -215,6 +228,18 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) } } + if config.SocketTxBufSize != 0 { + if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUF, int(config.SocketTxBufSize)); err != nil { + return newError("failed to set SO_SNDBUF/SO_SNDBUFFORCE").Base(err) + } + } + + if config.SocketRxBufSize != 0 { + if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUF, int(config.SocketRxBufSize)); err != nil { + return newError("failed to set SO_RCVBUF/SO_RCVBUFFORCE").Base(err) + } + } + return nil }