Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sockopts_lowat.go 833B

12345678910111213141516171819202122232425262728
  1. //go:build linux || darwin
  2. package network
  3. import (
  4. "syscall"
  5. "golang.org/x/sys/unix"
  6. )
  7. // setNotSentLowat sets TCP_NOTSENT_LOWAT to value bytes. The option
  8. // limits the amount of unsent data queued in the kernel write buffer:
  9. // once the unsent backlog drops below the threshold, the socket becomes
  10. // writable again, applying back-pressure to the relay loop instead of
  11. // piling up data in kernel buffers. This reduces per-connection memory
  12. // and bufferbloat.
  13. //
  14. // A non-positive value disables the call, leaving the kernel default in
  15. // effect (no upper bound beyond SO_SNDBUF).
  16. func setNotSentLowat(conn syscall.RawConn, value int) {
  17. if value <= 0 {
  18. return
  19. }
  20. conn.Control(func(fd uintptr) { //nolint: errcheck
  21. unix.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_NOTSENT_LOWAT, value) //nolint: errcheck
  22. })
  23. }