Browse Source

add socksopt rxtxbuf for windows

Shelikhoo 3 years ago
parent
commit
7dc8559f1c
1 changed files with 28 additions and 1 deletions
  1. 28 1
      transport/internet/sockopt_windows.go

+ 28 - 1
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
 }