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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

timeoutrwc.go 1007B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package proxy
  2. import (
  3. "io"
  4. "net"
  5. "time"
  6. )
  7. // TimeoutReadWriteCloser sets timeouts for read/write into underlying
  8. // network connection.
  9. type TimeoutReadWriteCloser struct {
  10. conn net.Conn
  11. readTimeout time.Duration
  12. writeTimeout time.Duration
  13. }
  14. // Read reads from connection
  15. func (t *TimeoutReadWriteCloser) Read(p []byte) (int, error) {
  16. t.conn.SetReadDeadline(time.Now().Add(t.readTimeout)) // nolint: errcheck, gas
  17. return t.conn.Read(p)
  18. }
  19. // Write writes into connection.
  20. func (t *TimeoutReadWriteCloser) Write(p []byte) (int, error) {
  21. t.conn.SetWriteDeadline(time.Now().Add(t.writeTimeout)) // nolint: errcheck, gas
  22. return t.conn.Write(p)
  23. }
  24. // Close closes underlying connection.
  25. func (t *TimeoutReadWriteCloser) Close() error {
  26. return t.conn.Close()
  27. }
  28. func newTimeoutReadWriteCloser(conn net.Conn, readTimeout, writeTimeout time.Duration) io.ReadWriteCloser {
  29. return &TimeoutReadWriteCloser{
  30. conn: conn,
  31. readTimeout: readTimeout,
  32. writeTimeout: writeTimeout,
  33. }
  34. }