From 631e37cc7042200fe2b3db34cfc46240b3856311 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 18 Nov 2020 19:00:07 +0700 Subject: [PATCH] only use syscalls on platforms that we're actually testing --- conn_ecn.go | 25 ++++++++++++++- conn_windows.go => conn_generic.go | 2 +- ..._helper_generic.go => conn_helper_linux.go | 2 +- conn_notwindows.go | 31 ------------------- 4 files changed, 26 insertions(+), 34 deletions(-) rename conn_windows.go => conn_generic.go (88%) rename conn_helper_generic.go => conn_helper_linux.go (87%) delete mode 100644 conn_notwindows.go diff --git a/conn_ecn.go b/conn_ecn.go index ecee4ac81..97db6e7a1 100644 --- a/conn_ecn.go +++ b/conn_ecn.go @@ -1,9 +1,11 @@ -// +build !windows +// +build darwin linux package quic import ( "errors" + "fmt" + "net" "syscall" "time" @@ -13,6 +15,27 @@ import ( const ecnMask uint8 = 0x3 +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 = syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF) + }); err != nil { + return 0, err + } + return size, serr +} + type ecnConn struct { ECNCapablePacketConn oobBuffer []byte diff --git a/conn_windows.go b/conn_generic.go similarity index 88% rename from conn_windows.go rename to conn_generic.go index 936537f2d..87bec24f6 100644 --- a/conn_windows.go +++ b/conn_generic.go @@ -1,4 +1,4 @@ -// +build windows +// +build !darwin,!linux package quic diff --git a/conn_helper_generic.go b/conn_helper_linux.go similarity index 87% rename from conn_helper_generic.go rename to conn_helper_linux.go index 1935e7ddf..1a798d4b4 100644 --- a/conn_helper_generic.go +++ b/conn_helper_linux.go @@ -1,4 +1,4 @@ -// +build !darwin,!windows +// +build linux package quic diff --git a/conn_notwindows.go b/conn_notwindows.go deleted file mode 100644 index bc9a2ef08..000000000 --- a/conn_notwindows.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build !windows - -package quic - -import ( - "errors" - "fmt" - "net" - "syscall" -) - -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 = syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF) - }); err != nil { - return 0, err - } - return size, serr -}