From 6dea7760cbfc77d09d176fafd9f03c66ddd85543 Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Wed, 17 Mar 2021 17:57:05 -0500 Subject: [PATCH] *WIP* this is just test code but works to increase throughput on windows significantly. the default windows buffers are 8192KB which is :( --- udp_windows.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/udp_windows.go b/udp_windows.go index dcfe884..06f5227 100644 --- a/udp_windows.go +++ b/udp_windows.go @@ -11,6 +11,32 @@ import ( func NewListenConfig(multi bool) net.ListenConfig { return net.ListenConfig{ Control: func(network, address string, c syscall.RawConn) error { + var controlErr error + err := c.Control(func(fd uintptr) { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, 999999); err != nil { + controlErr = fmt.Errorf("SO_SNDBUF failed: %v", err) + return + } + }) + if err != nil { + return err + } + if controlErr != nil { + return controlErr + } + err = c.Control(func(fd uintptr) { + if err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, 999999); err != nil { + controlErr = fmt.Errorf("SO_RCVBUF failed: %v", err) + return + } + }) + if err != nil { + return err + } + if controlErr != nil { + return controlErr + } + if multi { // There is no way to support multiple listeners safely on Windows: // https://docs.microsoft.com/en-us/windows/desktop/winsock/using-so-reuseaddr-and-so-exclusiveaddruse