simplify connection handling when setting the receive buffer

This commit is contained in:
Marten Seemann 2023-05-08 13:04:18 +03:00
parent 1cd78f131f
commit 600502ab06
6 changed files with 38 additions and 54 deletions

View file

@ -21,15 +21,18 @@ var _ = Describe("Can change the receive buffer size", func() {
c, err := net.ListenPacket("udp", "127.0.0.1:0")
Expect(err).ToNot(HaveOccurred())
forceSetReceiveBuffer(c, 256<<10)
defer c.Close()
syscallConn, err := c.(*net.UDPConn).SyscallConn()
Expect(err).ToNot(HaveOccurred())
forceSetReceiveBuffer(syscallConn, 256<<10)
size, err := inspectReadBuffer(c)
size, err := inspectReadBuffer(syscallConn)
Expect(err).ToNot(HaveOccurred())
// The kernel doubles this value (to allow space for bookkeeping overhead)
Expect(size).To(Equal(512 << 10))
forceSetReceiveBuffer(c, 512<<10)
size, err = inspectReadBuffer(c)
forceSetReceiveBuffer(syscallConn, 512<<10)
size, err = inspectReadBuffer(syscallConn)
Expect(err).ToNot(HaveOccurred())
// The kernel doubles this value (to allow space for bookkeeping overhead)
Expect(size).To(Equal(1024 << 10))