summaryrefslogtreecommitdiffhomepage
path: root/conn/controlfns_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'conn/controlfns_linux.go')
-rw-r--r--conn/controlfns_linux.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/conn/controlfns_linux.go b/conn/controlfns_linux.go
index 9e26d95..aff6245 100644
--- a/conn/controlfns_linux.go
+++ b/conn/controlfns_linux.go
@@ -15,6 +15,21 @@ import (
func init() {
controlFns = append(controlFns,
+ // Attempt to set the socket buffer size beyond net.core.{r,w}mem_max by
+ // using SO_*BUFFORCE. This requires CAP_NET_ADMIN, and is allowed here to
+ // fail silently - the result of failure is lower performance on very fast
+ // links or high latency links.
+ func(network, address string, c syscall.RawConn) error {
+ return c.Control(func(fd uintptr) {
+ // Set up to *mem_max
+ _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUF, socketBufferSize)
+ _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUF, socketBufferSize)
+ // Set beyond *mem_max if CAP_NET_ADMIN
+ _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUFFORCE, socketBufferSize)
+ _ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUFFORCE, socketBufferSize)
+ })
+ },
+
// Enable receiving of the packet information (IP_PKTINFO for IPv4,
// IPV6_PKTINFO for IPv6) that is used to implement sticky socket support.
func(network, address string, c syscall.RawConn) error {