github.com/tumi8/quic-go@v0.37.4-tum/sys_conn_helper_linux_test.go (about)

     1  // We need root permissions to use RCVBUFFORCE.
     2  // This test is therefore only compiled when the root build flag is set.
     3  // It can only succeed if the tests are then also run with root permissions.
     4  //go:build linux && root
     5  
     6  package quic
     7  
     8  import (
     9  	"net"
    10  	"os"
    11  
    12  	. "github.com/onsi/ginkgo/v2"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("forcing a change of send and receive buffer sizes", func() {
    17  	It("forces a change of the receive buffer size", func() {
    18  		if os.Getuid() != 0 {
    19  			Fail("Must be root to force change the receive buffer size")
    20  		}
    21  
    22  		c, err := net.ListenPacket("udp", "127.0.0.1:0")
    23  		Expect(err).ToNot(HaveOccurred())
    24  		defer c.Close()
    25  		syscallConn, err := c.(*net.UDPConn).SyscallConn()
    26  		Expect(err).ToNot(HaveOccurred())
    27  
    28  		const small = 256 << 10 // 256 KB
    29  		Expect(forceSetReceiveBuffer(syscallConn, small)).To(Succeed())
    30  
    31  		size, err := inspectReadBuffer(syscallConn)
    32  		Expect(err).ToNot(HaveOccurred())
    33  		//  The kernel doubles this value (to allow space for bookkeeping overhead)
    34  		Expect(size).To(Equal(2 * small))
    35  
    36  		const large = 32 << 20 // 32 MB
    37  		Expect(forceSetReceiveBuffer(syscallConn, large)).To(Succeed())
    38  		size, err = inspectReadBuffer(syscallConn)
    39  		Expect(err).ToNot(HaveOccurred())
    40  		//  The kernel doubles this value (to allow space for bookkeeping overhead)
    41  		Expect(size).To(Equal(2 * large))
    42  	})
    43  
    44  	It("forces a change of the send buffer size", func() {
    45  		if os.Getuid() != 0 {
    46  			Fail("Must be root to force change the send buffer size")
    47  		}
    48  
    49  		c, err := net.ListenPacket("udp", "127.0.0.1:0")
    50  		Expect(err).ToNot(HaveOccurred())
    51  		defer c.Close()
    52  		syscallConn, err := c.(*net.UDPConn).SyscallConn()
    53  		Expect(err).ToNot(HaveOccurred())
    54  
    55  		const small = 256 << 10 // 256 KB
    56  		Expect(forceSetSendBuffer(syscallConn, small)).To(Succeed())
    57  
    58  		size, err := inspectWriteBuffer(syscallConn)
    59  		Expect(err).ToNot(HaveOccurred())
    60  		//  The kernel doubles this value (to allow space for bookkeeping overhead)
    61  		Expect(size).To(Equal(2 * small))
    62  
    63  		const large = 32 << 20 // 32 MB
    64  		Expect(forceSetSendBuffer(syscallConn, large)).To(Succeed())
    65  		size, err = inspectWriteBuffer(syscallConn)
    66  		Expect(err).ToNot(HaveOccurred())
    67  		//  The kernel doubles this value (to allow space for bookkeeping overhead)
    68  		Expect(size).To(Equal(2 * large))
    69  	})
    70  })