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.

timeoutrwc.go 613B

12345678910111213141516171819202122232425262728293031
  1. package wrappers
  2. import (
  3. "io"
  4. "net"
  5. "time"
  6. "github.com/9seconds/mtg/config"
  7. )
  8. type TimeoutReadWriteCloser struct {
  9. conn net.Conn
  10. }
  11. func (t *TimeoutReadWriteCloser) Read(p []byte) (int, error) {
  12. t.conn.SetReadDeadline(time.Now().Add(config.TimeoutRead))
  13. return t.conn.Read(p)
  14. }
  15. func (t *TimeoutReadWriteCloser) Write(p []byte) (int, error) {
  16. t.conn.SetWriteDeadline(time.Now().Add(config.TimeoutWrite))
  17. return t.conn.Write(p)
  18. }
  19. func (t *TimeoutReadWriteCloser) Close() error {
  20. return t.conn.Close()
  21. }
  22. func NewTimeoutRWC(conn net.Conn) io.ReadWriteCloser {
  23. return &TimeoutReadWriteCloser{conn}
  24. }