set the UDP receive buffer size on Windows

This commit is contained in:
Marten Seemann 2020-11-21 17:48:26 +07:00
parent ed1956f5a9
commit 9d9307495b
3 changed files with 39 additions and 1 deletions

View file

@ -1,4 +1,4 @@
// +build !darwin,!linux
// +build !darwin,!linux,!windows
package quic

37
conn_windows.go Normal file
View file

@ -0,0 +1,37 @@
// +build windows
package quic
import (
"errors"
"fmt"
"net"
"syscall"
"golang.org/x/sys/windows"
)
func newConn(c net.PacketConn) (connection, error) {
return &basicConn{PacketConn: c}, nil
}
func inspectReadBuffer(c net.PacketConn) (int, error) {
conn, ok := c.(interface {
SyscallConn() (syscall.RawConn, error)
})
if !ok {
return 0, errors.New("doesn't have a SyscallConn")
}
rawConn, err := conn.SyscallConn()
if err != nil {
return 0, fmt.Errorf("couldn't get syscall.RawConn: %w", err)
}
var size int
var serr error
if err := rawConn.Control(func(fd uintptr) {
size, serr = windows.GetsockoptInt(windows.Handle(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
}); err != nil {
return 0, err
}
return size, serr
}

1
go.mod
View file

@ -17,6 +17,7 @@ require (
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299
google.golang.org/protobuf v1.23.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)