github.com/mikelsr/quic-go@v0.36.1-0.20230701132136-1d9415b66898/sys_conn_helper_linux.go (about)

     1  //go:build linux
     2  
     3  package quic
     4  
     5  import (
     6  	"syscall"
     7  
     8  	"golang.org/x/sys/unix"
     9  )
    10  
    11  const (
    12  	msgTypeIPTOS = unix.IP_TOS
    13  	ipv4PKTINFO  = unix.IP_PKTINFO
    14  )
    15  
    16  const batchSize = 8 // needs to smaller than MaxUint8 (otherwise the type of oobConn.readPos has to be changed)
    17  
    18  func forceSetReceiveBuffer(c syscall.RawConn, bytes int) error {
    19  	var serr error
    20  	if err := c.Control(func(fd uintptr) {
    21  		serr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_RCVBUFFORCE, bytes)
    22  	}); err != nil {
    23  		return err
    24  	}
    25  	return serr
    26  }
    27  
    28  func forceSetSendBuffer(c syscall.RawConn, bytes int) error {
    29  	var serr error
    30  	if err := c.Control(func(fd uintptr) {
    31  		serr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_SNDBUFFORCE, bytes)
    32  	}); err != nil {
    33  		return err
    34  	}
    35  	return serr
    36  }