github.com/quic-go/quic-go@v0.44.0/sys_conn_helper_linux_test.go (about) 1 //go:build linux 2 3 package quic 4 5 import ( 6 "errors" 7 "net" 8 "os" 9 10 "golang.org/x/sys/unix" 11 12 . "github.com/onsi/ginkgo/v2" 13 . "github.com/onsi/gomega" 14 ) 15 16 var ( 17 errGSO = &os.SyscallError{Err: unix.EIO} 18 errNotPermitted = &os.SyscallError{Syscall: "sendmsg", Err: unix.EPERM} 19 ) 20 21 var _ = Describe("forcing a change of send and receive buffer sizes", func() { 22 It("forces a change of the receive buffer size", func() { 23 if os.Getuid() != 0 { 24 Skip("Must be root to force change the receive buffer size") 25 } 26 27 c, err := net.ListenPacket("udp", "127.0.0.1:0") 28 Expect(err).ToNot(HaveOccurred()) 29 defer c.Close() 30 syscallConn, err := c.(*net.UDPConn).SyscallConn() 31 Expect(err).ToNot(HaveOccurred()) 32 33 const small = 256 << 10 // 256 KB 34 Expect(forceSetReceiveBuffer(syscallConn, small)).To(Succeed()) 35 36 size, err := inspectReadBuffer(syscallConn) 37 Expect(err).ToNot(HaveOccurred()) 38 // The kernel doubles this value (to allow space for bookkeeping overhead) 39 Expect(size).To(Equal(2 * small)) 40 41 const large = 32 << 20 // 32 MB 42 Expect(forceSetReceiveBuffer(syscallConn, large)).To(Succeed()) 43 size, err = inspectReadBuffer(syscallConn) 44 Expect(err).ToNot(HaveOccurred()) 45 // The kernel doubles this value (to allow space for bookkeeping overhead) 46 Expect(size).To(Equal(2 * large)) 47 }) 48 49 It("forces a change of the send buffer size", func() { 50 if os.Getuid() != 0 { 51 Skip("Must be root to force change the send buffer size") 52 } 53 54 c, err := net.ListenPacket("udp", "127.0.0.1:0") 55 Expect(err).ToNot(HaveOccurred()) 56 defer c.Close() 57 syscallConn, err := c.(*net.UDPConn).SyscallConn() 58 Expect(err).ToNot(HaveOccurred()) 59 60 const small = 256 << 10 // 256 KB 61 Expect(forceSetSendBuffer(syscallConn, small)).To(Succeed()) 62 63 size, err := inspectWriteBuffer(syscallConn) 64 Expect(err).ToNot(HaveOccurred()) 65 // The kernel doubles this value (to allow space for bookkeeping overhead) 66 Expect(size).To(Equal(2 * small)) 67 68 const large = 32 << 20 // 32 MB 69 Expect(forceSetSendBuffer(syscallConn, large)).To(Succeed()) 70 size, err = inspectWriteBuffer(syscallConn) 71 Expect(err).ToNot(HaveOccurred()) 72 // The kernel doubles this value (to allow space for bookkeeping overhead) 73 Expect(size).To(Equal(2 * large)) 74 }) 75 76 It("detects GSO errors", func() { 77 Expect(isGSOError(errGSO)).To(BeTrue()) 78 Expect(isGSOError(nil)).To(BeFalse()) 79 Expect(isGSOError(errors.New("test"))).To(BeFalse()) 80 }) 81 })