mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-04 23:45:34 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build unix
|
|
|
|
package magicsock
|
|
|
|
import (
|
|
"net"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"tailscale.com/types/nettype"
|
|
)
|
|
|
|
func TestTrySetSocketBuffer(t *testing.T) {
|
|
c, err := net.ListenPacket("udp", ":0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer c.Close()
|
|
|
|
rc, err := c.(*net.UDPConn).SyscallConn()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
getBufs := func() (int, int) {
|
|
var rcv, snd int
|
|
rc.Control(func(fd uintptr) {
|
|
rcv, err = syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
|
|
if err != nil {
|
|
t.Errorf("getsockopt(SO_RCVBUF): %v", err)
|
|
}
|
|
snd, err = syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF)
|
|
if err != nil {
|
|
t.Errorf("getsockopt(SO_SNDBUF): %v", err)
|
|
}
|
|
})
|
|
return rcv, snd
|
|
}
|
|
|
|
curRcv, curSnd := getBufs()
|
|
|
|
trySetSocketBuffer(c.(nettype.PacketConn), t.Logf)
|
|
|
|
newRcv, newSnd := getBufs()
|
|
|
|
if curRcv > newRcv {
|
|
t.Errorf("SO_RCVBUF decreased: %v -> %v", curRcv, newRcv)
|
|
}
|
|
if curSnd > newSnd {
|
|
t.Errorf("SO_SNDBUF decreased: %v -> %v", curSnd, newSnd)
|
|
}
|
|
|
|
// On many systems we may not increase the value, particularly running as a
|
|
// regular user, so log the information for manual verification.
|
|
t.Logf("SO_RCVBUF: %v -> %v", curRcv, newRcv)
|
|
t.Logf("SO_SNDBUF: %v -> %v", curRcv, newRcv)
|
|
}
|