forked from quic-go/quic-go
add a function to set the UDP send buffer size
This function is the equivalent to the function used to set the UDP receive buffer size. It's so similar that code generation is used to make a copy of the setReceiveBuffer function.
This commit is contained in:
@@ -13,8 +13,8 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Can change the receive buffer size", func() {
|
||||
It("Force a change (if we have CAP_NET_ADMIN)", func() {
|
||||
var _ = Describe("forcing a change of send and receive buffer sizes", func() {
|
||||
It("forces a change of the receive buffer size", func() {
|
||||
if os.Getuid() != 0 {
|
||||
Fail("Must be root to force change the receive buffer size")
|
||||
}
|
||||
@@ -24,17 +24,47 @@ var _ = Describe("Can change the receive buffer size", func() {
|
||||
defer c.Close()
|
||||
syscallConn, err := c.(*net.UDPConn).SyscallConn()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
forceSetReceiveBuffer(syscallConn, 256<<10)
|
||||
|
||||
const small = 256 << 10 // 256 KB
|
||||
Expect(forceSetReceiveBuffer(syscallConn, small)).To(Succeed())
|
||||
|
||||
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))
|
||||
Expect(size).To(Equal(2 * small))
|
||||
|
||||
forceSetReceiveBuffer(syscallConn, 512<<10)
|
||||
const large = 32 << 20 // 32 MB
|
||||
Expect(forceSetReceiveBuffer(syscallConn, large)).To(Succeed())
|
||||
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))
|
||||
Expect(size).To(Equal(2 * large))
|
||||
})
|
||||
|
||||
It("forces a change of the send buffer size", func() {
|
||||
if os.Getuid() != 0 {
|
||||
Fail("Must be root to force change the send buffer size")
|
||||
}
|
||||
|
||||
c, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer c.Close()
|
||||
syscallConn, err := c.(*net.UDPConn).SyscallConn()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
const small = 256 << 10 // 256 KB
|
||||
Expect(forceSetSendBuffer(syscallConn, small)).To(Succeed())
|
||||
|
||||
size, err := inspectWriteBuffer(syscallConn)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// The kernel doubles this value (to allow space for bookkeeping overhead)
|
||||
Expect(size).To(Equal(2 * small))
|
||||
|
||||
const large = 32 << 20 // 32 MB
|
||||
Expect(forceSetSendBuffer(syscallConn, large)).To(Succeed())
|
||||
size, err = inspectWriteBuffer(syscallConn)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// The kernel doubles this value (to allow space for bookkeeping overhead)
|
||||
Expect(size).To(Equal(2 * large))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user