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.

init_tcp.go 667B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. func InitTCP(conn net.Conn, readBufferSize, writeBufferSize int) error {
  7. tcpConn := conn.(*net.TCPConn) //nolint: forcetypeassert
  8. if err := tcpConn.SetNoDelay(true); err != nil {
  9. return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err)
  10. }
  11. if err := tcpConn.SetReadBuffer(readBufferSize); err != nil {
  12. return fmt.Errorf("cannot set read buffer size: %w", err)
  13. }
  14. if err := tcpConn.SetWriteBuffer(writeBufferSize); err != nil {
  15. return fmt.Errorf("cannot set write buffer size: %w", err)
  16. }
  17. if err := tcpConn.SetKeepAlive(true); err != nil {
  18. return fmt.Errorf("cannot enable keep-alive: %w", err)
  19. }
  20. return nil
  21. }