setbuffer_linux.go 651 B

123456789101112131415161718192021222324
  1. //go:build linux
  2. // +build linux
  3. package socket
  4. import "golang.org/x/sys/unix"
  5. // setReadBuffer wraps the SO_RCVBUF{,FORCE} setsockopt(2) options.
  6. func (c *Conn) setReadBuffer(bytes int) error {
  7. err := c.SetsockoptInt(unix.SOL_SOCKET, unix.SO_RCVBUFFORCE, bytes)
  8. if err != nil {
  9. err = c.SetsockoptInt(unix.SOL_SOCKET, unix.SO_RCVBUF, bytes)
  10. }
  11. return err
  12. }
  13. // setWriteBuffer wraps the SO_SNDBUF{,FORCE} setsockopt(2) options.
  14. func (c *Conn) setWriteBuffer(bytes int) error {
  15. err := c.SetsockoptInt(unix.SOL_SOCKET, unix.SO_SNDBUFFORCE, bytes)
  16. if err != nil {
  17. err = c.SetsockoptInt(unix.SOL_SOCKET, unix.SO_SNDBUF, bytes)
  18. }
  19. return err
  20. }